所以,在编程方面我是个十足的傻瓜,上周末才开始学习python。无论如何,作为Youtube教程中的一个挑战,我本来打算写一个程序,可以找到定义范围内的所有数字,当除以4时,会给我0提示,然后它们就会被列出。所以我把它放得更远一点,下面是我目前所得到的。在# Program that let's you find all numbers in any range defined by user
# that can be divided without any reminder by the number also defined by user
print('Find all numbers in range...')
while True:
try:
x = int(input('From: ')) # begining of the range
y = int(input('.. to: ')) # end of the range
z = int(input('.. that can be divided by: ')) # value of the number to divide by
except ValueError: # in case of a nonint input
print('You should enter a valid number!')
continue
for a in range(x, y):
try:
if a % z == 0:
print(a, [a / z], end = ' ')
except ZeroDivisionError: # issue with implementing this exception
pass
为了避免使用pass语句,我尝试
^{pr2}$
它打印字符串(x,y)次。有什么建议吗?非常感谢