简体   繁体   English

如何继续这个 Python 作业?

[英]How to continue with this Python homework?

Write a program that uses a while loop.编写一个使用 while 循环的程序。 Process input that uses a sentinel value to indicate the end of input使用标记值指示输入结束的处理输入

Write a program that reads a series of numbers from standard input and prints out the sum of those values.编写一个程序,从标准输入中读取一系列数字并打印出这些值的总和。 A sentinel value of -999 will indicate the end of the input values. -999 的标记值将指示输入值的结束。 Do not include the sentinel value in the sum.不要在总和中包括标记值。

For example:例如:

示例快照

Can anyone help me with this?谁能帮我这个? This is what I have tried这是我尝试过的

user_input = 1
    while user_input = -999:
        user_input = int(input())

You can try this, This code portion will break when it reaches the value till it matches the sentinel.你可以试试这个,这段代码在达到值时会中断,直到它匹配哨兵。

value = 0
while True:
    old_value, value = value, way_to_new_value
    if value == old_value: break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM