1
我正在編寫一個應該添加用戶輸入的所有正值的程序,程序應該循環直到他/她輸入負數。程序可以平穩地循環,但是它包含總和中的負數。任何幫助表示讚賞!在Python中創建排除
def main():
X=0
Y=0
print("I can add the sum of all positive numbers")
X = int (input ("Please enter a positve number between 0 and infinity: "))
if X > 0:
while Y >= 0:
print("I can add the sum of all positive numbers")
Y = int(input("Please enter a positive number between 0 and infinity: "))
X = X + Y
print("The sum of the numbers you entered is: ", X)
else:
print("Sorry I can only add positive numbers")
main()