+ 1

Can someone please tell me why my try-except isn't working? BTW, couldn't fit the entire code in.

import random #adding function def add(num1,num2): return num1 + num2 #subtracting function def sub(num1, num2): return num1 - num2 #multiplying function def mul(num1, num2): return num1 * num2 #dividing function def div(num1, num2): return num1 / num2 def main(): try: userInput = int(input("Enter a number from 1 to 10.\n") except Value Error: print("Invalid input. Try again.") print("The computer will make a random calculation", userInput, "times.") runCode = 1 print("First calculation:") while(runCode <= userInput): num1 = random.randint(1,10) num2 = random.randint(1,10) print(num1) print(num2) operation = random.randint(1,4) if(operation == 1): print("Adding...") print(add(num1, num2)) print("Next calculation:") elif(operation == 2): print("Subtracting...") print(sub(num1,num2)) print("Next calculation:")

5th Aug 2018, 5:55 PM
Thomas Wald
Thomas Wald - avatar
2 Antworten
+ 6
You have "Value Error". I think you meant to put "ValueError".
5th Aug 2018, 7:23 PM
Fox
Fox - avatar
+ 2
Hello! You can use inserting-code feature to share your entire code without any concern about fitting.
5th Aug 2018, 6:14 PM
xXx
xXx - avatar