0

Why does line produce an error? Warning\Error File "file.py", line 13 num1 = float(input("Enter a number:"))

11th Apr 2017, 12:52 AM
Shedrick Williams
Shedrick Williams - avatar
10 Réponses
+ 2
Fill in the blanks to handle all possible exceptions. try: num1 = input(":") num2 = input(":") print(float(num1)/float(num2)) except: print("Invalid input")
8th Sep 2019, 10:34 PM
OUSSAMA ROMDHANI
OUSSAMA ROMDHANI - avatar
+ 1
ok sorry heres full code while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) print("Your answer is (num1 + num2)") elif user_input == "subtract" num3 = float(input("Enter a number")) num4 = float(input("Enter another number")) print("Your answer is (num3 - num4)") elif user_input == "multiply": num5 = float(input("Enter a number")) num6 = float(input("Enter another number")) print("Your anser is (num5 * num6)") elif user_input == "divide": num7 = float(input("Enter a number")) num8 = float(input("Enter another number")) print("Your answer is (num7/num8)")
11th Apr 2017, 6:11 AM
Shedrick Williams
Shedrick Williams - avatar
0
do you see an EOF error in this code as well?
11th Apr 2017, 5:18 PM
Shedrick Williams
Shedrick Williams - avatar
0
try: num1 = input(":") num2 = input(":") print(float(num1)/float(num2)) except: print("Invalid input")
22nd Sep 2022, 3:39 PM
ABDUL WAHAB
0
try: num1 = input(":") num2 = input(":") print(float(num1)/float(num2)) except: print("Invalid input")
30th Mar 2023, 10:32 PM
المهندس أحمد
المهندس أحمد - avatar
- 1
that line/statement -> num1 = float(input("Enter a number:")) doesn't give any error unless u input invalid input(string) this information is not enough to figure out the issue.show full code or code block.
11th Apr 2017, 3:51 AM
Eranga
Eranga - avatar
- 1
There are many syntax errors and indentation issues.. Try this. In Python indentation is important to mark the code scope/block. while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) print("Your answer is (num1 + num2)") elif user_input == "subtract": num3 = float(input("Enter a number")) num4 = float(input("Enter another number")) print("Your answer is (num3 - num4)") elif user_input == "multiply": num5 = float(input("Enter a number")) num6 = float(input("Enter another number")) print("Your anser is (num5 * num6)") elif user_input == "divide": num7 = float(input("Enter a number")) num8 = float(input("Enter another number")) print("Your answer is (num7/num8)")
11th Apr 2017, 6:24 AM
Eranga
Eranga - avatar
- 1
Fill in the blanks to handle all possible exceptions. try: num1 = input(":") num2 = input(":") print(float(num1)/float(num2)) except: print("Invalid input")
4th Oct 2021, 2:22 AM
Khyra
- 2
yaaaaa the question is awsome
1st Nov 2019, 10:22 AM
sumanth kunchala
 sumanth kunchala - avatar
- 2
try: except:
11th Feb 2021, 6:12 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar