任何帮助都将不胜感激。我是刚学Python的。这是我必须完成的练习。我已经认真地给了我大约3到4个小时的时间,所以不用担心我是在“要求别人为我做我的工作”。这是我的练习和我到目前为止所做的。我一直在困惑这些,并“黑客”我的方式通过学习过程。如果您了解整个代码,并且不介意包括它,我将非常感谢它。练习:编写一个循环程序,要求用户输入正数。用户应该输入一个负号来表示系列的结束。当用户结束程序时(输入一个负数),应该显示正数之和。这是我到目前为止所拥有的。
# The main function.
def main():
# Variable to control the outer loop.
another = 'y'
while another == 'y' or another == 'Y':
numbers()
another = input('Run this program again?\n\
Enter y for yes.')
def numbers():
positive = int(input('Enter a positive number: '))
while positive > 0:
positive = int(input('Enter a positive number, or enter a\n\
negative number to end and calculate the sum: '))
positive = int(input('Enter a positive number: '))
while positive < 0:
for i in range (positive):
print(i)
# Call the main function.
main()发布于 2013-10-27 19:43:49
那麽:
# The main function.
def main():
mysum = 0
while True:
positive = int(input('Enter a positive number, or enter a\n\
negative number to end and calculate the sum: '))
if positive < 0:
print mysum
return
mysum = mysum + positive
# Call the main function.
main()https://stackoverflow.com/questions/19622465
复制相似问题