反计划程序不能正常使用Python 3

时间:2018-05-28 12:48:44

标签: python-3.x counter

我想制作一台获得一定金额的时间表机器,添加金额,说出金额是多少,并询问是否要通过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

1 个答案:

答案 0 :(得分:0)

我在捕获用户输入后发现代码中存在小错误,即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()