【发布时间】:2019-11-16 23:09:47
【问题描述】:
这是我使用 Python 编程的第二周,之前从未编写过任何东西。一步一步欣赏。
我不知道从哪里开始。
【问题讨论】:
-
到目前为止你得到了什么?你知道怎么读一个数字吗?你知道如何读取多个数字吗?你知道循环吗?向我们展示您拥有的任何代码。
-
可能从接收用户的整数开始(提示:这个操作包括两个步骤)。
标签: python python-3.x
这是我使用 Python 编程的第二周,之前从未编写过任何东西。一步一步欣赏。
我不知道从哪里开始。
【问题讨论】:
标签: python python-3.x
try:
count = 0
while True:
user = int(input('Insert Number: '))
count += user
if user == 0:
break
print(count)
except ValueError:
print('Please Insert Numbers Only!')
【讨论】:
首先,使用 while 循环作为输入。除非您需要进一步的帮助,否则我会将总结部分留给您:
cc = int(input("Enter an integer to sum. Press 0 to to end and start the summation:"))
while cc != 0:
cc = int(input("Enter an integer to sum. Press 0 to to end and start the summation:"))
【讨论】:
def is_int(num):
try:
return int(num)
except:
return False
total = 0
while True:
in_user = is_int(input("input integer: "))
if in_user is not False:
total += in_user
if in_user is 0:
break
print(total)
【讨论】: