Python Forum
How to run a loop till half of the string...without using inbuilt function
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run a loop till half of the string...without using inbuilt function
#1
please give a runnabl sample of your code with the full error text or a clear description of the problem

I know, i was asking some basic question...but i am new to python launguage and not able to crack this basic code..please help me.thanq
str="titit"
a=len(str)
for l in str[:a/2]
    for m in str[a,-1]:
        if l==m:
            if l!=len(str)/2:
                break
            else:
                
        else:
            print("not a palindrome")
Error:
File "<ipython-input-120-c3db7da8370e>", line 3 for l in str[:a/2] ^ SyntaxError: invalid syntax
Reply
#2
Constructs which start a block (for loops, while loops, if, elif, else, def, etc) all need a colon at the end of the line.  The arrow is pointing to where the colon is expected to be.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert a string to a function mikepy 8 2,504 May-13-2022, 07:28 PM
Last Post: mikepy
  Loop through a list of string oldtrafford 4 1,470 Mar-24-2022, 05:30 PM
Last Post: deanhystad
  Loop through a list of string oldtrafford 3 1,695 Feb-15-2022, 04:42 PM
Last Post: snippsat
  loop for dynamic cut string - cleaner way? korenron 4 1,925 Nov-22-2021, 02:30 PM
Last Post: korenron
  [SOLVED] Read text file from some point till EOF? Winfried 1 1,950 Oct-10-2021, 10:29 PM
Last Post: Winfried
  I am trying to reverse a string using loop codinglearner 4 2,160 Sep-28-2021, 10:46 PM
Last Post: Pedroski55
  Convert string to JSON using a for loop PG_Breizh 3 2,964 Jan-08-2021, 06:10 PM
Last Post: PG_Breizh
  Checkbox half working Milfredo 12 4,216 Sep-19-2020, 10:43 PM
Last Post: Milfredo
  Exit Function - loop Tetsuo30 2 2,057 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  String slicing and loop iteration divyansh 9 4,718 Jun-07-2020, 10:29 PM
Last Post: divyansh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020