python 如何中断循环程序_如果循环中有一个循环,如何中断程序?

我一直在尝试在Python上做一个对数计算器。我离完成它只有一步之遥。代码如下:import math

print("Welcome to logarithm calculator")

while True:

try:

inlog = int(input("Enter any value greater than zero to lookup its logarithm to the base 10\n"))

outlog = math.log(inlog, 10)

print(outlog)

# Here, the program will ask the user to quit or to continue

print("Want to check another one?")

response = input("Hit y for yes or n for no\n")

if response == ("y" or "Y"):

pass

elif response == ("n" or "N"):

break

else:

#I don't know what to do here so that the program asks the user to quit or continue if the response is invalid?

except ValueError:

print("Invalid Input: Make sure your number is greater than zero and no alphabets. Try Again.")

直到“我想再次以”或“我想”的方式回答“程序”之后。若我在这里添加另一个while循环,那个么若用户输入“y”,那个么使用pass语句就可以了。但是当用户回答为“n”时,它不会破坏程序,因为它会让我们进入外循环。

那么如何解决这个问题呢?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值