简单的除法计算器
print("Please give me two numbers, and I'll divide them.")
print("Enter 'q' to quit")
while True:
first_number = input("Please input the first number:")
if first_number == "q":
break
second_number = input("Please input the second number: ")
if second_number == "q":
break
try:
answer = int(first_number) / int(second_number)
except ZeroDivisionError:
print("You can't divide by 0!")
except ValueError:
print("You can only input integers!")
else:
print(answer)
break
初学python,感觉python的逻辑很清晰,逐句执行,下面改一下代码,大家觉得输出会有什么不同吗?
print("Please give me two numbers, and I'll divide them.")
print("Enter 'q' to quit")
while True:
first_number = input("Please input the first number:")
second_number = input("Please input the second number: ")
if first_number == "q":
break
if second_number == "q":
break
try:
answer = int(first_number) / int(second_number)
except ZeroDivisionError:
print("You can't divide by 0!")
except ValueError:
print("You can only input integers!")
else:
print(answer)
break