计数器程序不起作用 Python 3



我想做一个时间表机器,它得到一定的金额,加上金额,说出总和是多少,并询问您是否要通过 Y/n 进行。

我输入"n"继续,但由于某种原因它停止了?

有人可以帮助我吗

这是我的代码:

print('''Welcome to loop, here, you shall be able to experience you multiples up to a certain amount
e.g my multiples of 9s.''')
p=input('Increasing in? ')
a=0
b=1
while True:
a+=int(p)
print(str(a)+', this is '+str(p)+'*' + str(b))
b+=1
s=input('Stop? [Y/n] ONLY! ')
if s.lower() or s.upper() == 'y'
print('Thank you for using loop, See you again soon. ')
break
elif s.lower() or upper() == 'n':
pass

捕获用户输入后,我发现您的代码中存在小错误,即 Y/n if 条件似乎是错误的。 下面的代码应该可以满足您的要求

def test():
p = input("Increasing in")
a = 0
b = 1
while True:
a += int(p)
print(str(a) + ', this is ' + str(p) + '*' + str(b))
b += 1
s = input('Stop [Y/n] ONLY! ')
if(s == 'y' or s.lower() == 'y'):
print('Thank you for using loop')
break
else:
pass
test()

最新更新