正如我之前所说的,我是一个初学者,试图在大学课程中学习Python,但是他们教给我们的东西并不总是适用于现实世界,当我试图研究解决方案时,没有什么可以找到的。总之,我最近的问题是:
This is a tricky challenge for you.
We will pass in a value N. N can be positive or negative.
If N is positive then output all values from N down to and excluding 0.
If N is negative, then output every value from N up to and excluding 0.
and the starting code is:
# Get N from the command line
import sys
N = int(sys.argv[1])
# Your code goes here
counter = 0
while counter <= N:
print(counter)
counter = counter + 1
elif counter >= N:
print(N+counter)
counter = counter - 1
My solution produced an error:
SyntaxError: unexpected EOF while parsing
There is an error is your program.
老实说,我不知道从哪里开始,因为我们的教科书没有涵盖这些挑战。提前感谢您在这件事上提供的任何帮助。顺便说一句,我的代码是在Codio中输入的,必须传入Codio的IDE。在
这里的主要问题是你有一段时间和一个elif。Elif与其他if语句一起使用。
例如:
我想你是想这么做:
^{pr2}$最后几件事:
While循环版本
^{pr2}$相关问题 更多 >
编程相关推荐