Dank Dorito
Dank Dorito

Reputation: 11

SyntaxError 255 On List

In this piece of code:

n = int(input())

for i in the range(0, n):
    x = input()

    for y in range(0, len(string)):

        if y % 2 == 0:
            print(string[y], end='')

    print("", end='')

    for y in range(0, len(string)):

        if y % 2 != 0:
            print(string[y], end='')

    print("")

Don't know why it came so messed up.

Error: File "solution.py", line 3 for i in the range(0, n): ^ SyntaxError: invalid syntax

Upvotes: 0

Views: 875

Answers (2)

alex
alex

Reputation: 113

There are a few errors in your code . The variable"x" name should be 'strings', if you dont change it's name those for wont do anything and a previous error with the for.

for i in range(0,n):
    strings=input()
    for y in range(0,len(strings)):
         #the code....

Upvotes: 0

Prune
Prune

Reputation: 77847

"in the range" is not legal Python. Remove "the".

You have a variety of other problems in the code. I strongly recommend that you adopt incremental programming, especially at this stage. Start by writing a couple of lines of code, just enough to do something, such as read and print an integer. Once those lines work, then add a couple more that run through a trivial for loop. Continue this, a couple of lines at a time, adding just one "baby step" to your program, seeing minor successes as you go. For instance, start with

n = int(input("How many times?")
print "n=", n

Next, add the loop:

for i in range(0, n):
    print "i=", i

Then go on to the serial input -- again, properly labeled:

    x = input("Give me number", i)
    print x, type(x)

See how this works?

Upvotes: 3

Related Questions