編寫一個Python程序,讀入一系列正整數並寫出所有小於25的整數乘積和所有整數整數大於或等於25.使用0作爲標記值。Python:分離少於25個int和大於25個int輸入,然後使用這些數字
def main():
user_input = 1
while user_input != 0:
user_input = int(input("Enter positive integers, then type 0 when finnished. "))
if (user_input) < 25:
product = 1
product = (user_input) * product
else:
(user_input) >= 25
sum = 0
sum = (user_input) + sum
print('The product off all the integers less than 25 is ', product, "and the sum of all the integers greater than 25 is ", sum, ".")
main()
這是我到目前爲止。這是我在計算機科學課上的第一個Python代碼。
我的主要障礙是前哨值必須爲零,並且我的user_input乘以產品,它只是將所有東西都歸零。
你使用numpy的? – EL3PHANTEN
爲什麼不測試零*以前*檢查它是高於還是低於25? – jonrsharpe
您需要在while循環之外初始化您的標記值 – AChampion