Python Forum
Beginner. Calculator problem ¯\_(ツ)_/¯
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner. Calculator problem ¯\_(ツ)_/¯
#1
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.
#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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  calculator app problem jacksfrustration 1 188 Apr-11-2024, 03:09 PM
Last Post: deanhystad
  small beginner problem FelixReiter 2 1,867 Nov-17-2020, 03:26 PM
Last Post: FelixReiter
  Beginner having Syntax Error problem RyanHo 3 2,381 Sep-10-2020, 08:33 AM
Last Post: cnull
  Beginner, my recursion returns None, and related problem zpacemanzpiff 2 1,808 Jul-02-2020, 04:25 AM
Last Post: zpacemanzpiff
  BEGINNER: My calculator doesnt work iskov 5 3,211 Oct-09-2019, 07:45 AM
Last Post: buran
  Beginner problem, replace function with for loop Motley_Cow 9 4,633 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow
  Beginner problem in python script Cedmo 3 2,783 Jul-04-2019, 08:22 PM
Last Post: Cedmo
  Beginner Problem python 2.7 Jonathan_levy 2 2,686 Jul-04-2018, 08:46 PM
Last Post: ichabod801
  Beginner Problem python 2.7 Jonathan_levy 2 2,725 Jul-03-2018, 11:58 AM
Last Post: gruntfutuk
  Calculator problem BeginnerCoderPaero 4 3,370 Jun-29-2018, 09:21 AM
Last Post: BeginnerCoderPaero

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020