开发者

Two syntax errors in my python code

I've written a small program in python 3.2 that takes numbers as an input and counts them by a user chosen amount. For some reason I've been getting some syntax errors.

Here's th开发者_Python百科e code.

    start = input(int("Starting number: "))
    ending = input(int("Ending number: "))
    tick = input(int(("Interval: "))
    print("Counting by", tick)
    print(for i in range(start, ending, tick):
        print(i, end = " ")

The errors occur in the print functions for "Counting by" and for i in range. In addition the colon on the fifth line is also seen as a syntax error.


You have an unmatched '(' in line 3.

Your for loop shouldn't be in a print function call.

This isn't a syntax problem, I don't think, but you should have int(input(...)) instead of input(int(...)).


start = int(input("Starting number: "))
ending = int(input("Ending number: "))
tick = int(input("Interval: "))
print("Counting by", tick)
for i in range(start, ending, tick):
    print(i, end = " ")


start = input(int("Starting number: "))
ending = input(int("Ending number: "))
tick = input(int(("Interval: ")))
print("Counting by %d" % tick)
for i in range(start, ending, tick):
    print(i, end = " ")

Still a syntax error on the last line, but that's because I'm not clear what you're trying to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜