Feb-15-2018, 11:01 AM
(This post was last modified: Feb-15-2018, 11:21 AM by stykus1992.)
Hello guys, can someone help me understand what have I done wrong here :D
In last part, when it asks "Do u want some more?" and instead of writing "1" or "2" you type some random shit everything is fine, but if you type "3", "4" etc. it says "Wrong" as it should be but then after asking again "Do you want some more" and pressing "1" it just shuts down without continuation.
Any suggestion would be more than welcome! :)
def main():
exitInput = False
while not exitInput:
correctInput = False
while not correctInput:
try:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
operation = int(input("What you want to do: 1 to add , 2 to subtract , 3 to multiply , 4 to divide. Enter number: "))
correctInput = True
except:
print("Invalid operation! Try again.")
if (operation == 1):
print("Result:")
print(add(num1, num2))
elif (operation == 2):
print("Result:")
print(sub(num1, num2))
elif (operation == 3):
print("Result:")
print(multi(num1, num2))
elif (operation == 4):
print("Result:")
print(div(num1, num2))
else:
print("You must enter valid operation")
wtfInput = False
while not wtfInput:
try:
exitingNote = int(input('Do u want some more? Type 1 for "Yes" or 2 for "No": '))
if (exitingNote == 1):
print('Ok')
exitInput = False
break
elif (exitingNote == 2):
print('Bye bye!')
continue
else:
print("Wrong")
wtfInput = False
except:
print("wtf?")
wtfInput = False
main()
I am not sure how to explain it better than I already did. If I put any answer to "Do u want some more" other number(only number, letters are ok) than "1" and "2" it returns to the question "Do u want some more" but whatever the answer is, it always shuts down.
In last part, when it asks "Do u want some more?" and instead of writing "1" or "2" you type some random shit everything is fine, but if you type "3", "4" etc. it says "Wrong" as it should be but then after asking again "Do you want some more" and pressing "1" it just shuts down without continuation.
Any suggestion would be more than welcome! :)
def main():
exitInput = False
while not exitInput:
correctInput = False
while not correctInput:
try:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
operation = int(input("What you want to do: 1 to add , 2 to subtract , 3 to multiply , 4 to divide. Enter number: "))
correctInput = True
except:
print("Invalid operation! Try again.")
if (operation == 1):
print("Result:")
print(add(num1, num2))
elif (operation == 2):
print("Result:")
print(sub(num1, num2))
elif (operation == 3):
print("Result:")
print(multi(num1, num2))
elif (operation == 4):
print("Result:")
print(div(num1, num2))
else:
print("You must enter valid operation")
wtfInput = False
while not wtfInput:
try:
exitingNote = int(input('Do u want some more? Type 1 for "Yes" or 2 for "No": '))
if (exitingNote == 1):
print('Ok')
exitInput = False
break
elif (exitingNote == 2):
print('Bye bye!')
continue
else:
print("Wrong")
wtfInput = False
except:
print("wtf?")
wtfInput = False
main()
I am not sure how to explain it better than I already did. If I put any answer to "Do u want some more" other number(only number, letters are ok) than "1" and "2" it returns to the question "Do u want some more" but whatever the answer is, it always shuts down.
#returns the sum of num1 and num2 def add(num1, num2): return num1 + num2 #returns the sub of num1 and num2 def sub(num1, num2): return num1 - num2 #returns the multi of num1 and num2 def multi(num1, num2): return num1 * num2 #returns the div of num1 and num2 def div(num1, num2): return num1 / num2 def main(): exitInput = False while not exitInput: correctInput = False while not correctInput: try: num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) operation = int(input("What you want to do: 1 to add , 2 to subtract , 3 to multiply , 4 to divide. Enter number: ")) correctInput = True except: print("Invalid operation! Try again.") if (operation == 1): print("Result:") print(add(num1, num2)) elif (operation == 2): print("Result:") print(sub(num1, num2)) elif (operation == 3): print("Result:") print(multi(num1, num2)) elif (operation == 4): print("Result:") print(div(num1, num2)) else: print("You must enter valid operation") wtfInput = False while not wtfInput: try: exitingNote = int(input('Do u want some more? Type 1 for "Yes" or 2 for "No": ')) if (exitingNote == 1): print('Ok') exitInput = False break elif (exitingNote == 2): print('Bye bye!') continue else: print("Wrong") wtfInput = False except: print("wtf?") wtfInput = False main()