首页 > 解决方案 > Read inputs(nummbers) till a input (Stop) is given

问题描述

i want to Read inputs(nummbers) till a input (Stop) is given and then add all the nummber that are given before the input stop. idk what to do. here i tried but doesnt work at all.

input2 = input()
input3 = input()
input4 = input()
input5 = input()
som = 0

while input1 or input2 or input3 or input4 or input5 != "stop":
    som = int(input1) + int(input2) + int(input3) + int(input4) + int(input5)
    print(som)
    break
if input1 or input2 or input3 or input4 or input5 == "stop":
    print(som, "Stop")

标签: pythonfor-loopwhile-loop

解决方案


在循环语句中包含输入:

som = 0
while True:
    number = input()
    if number == "stop":
        break
    som += int(number)
print(som)

推荐阅读