开发者

Two syntax errors in my python code

开发者 https://www.devze.com 2023-03-16 13:23 出处:网络
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.

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

精彩评论

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