Why am I getting the following error? ValueError: could not convert string to float: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why am I getting the following error? ValueError: could not convert string to float:

#Comparing two rectangles R_1_L = float( input("Please enter the length of Rectangle 1: ") ) R_1_W = float( input("Please enter the weidth of Rectangle 1: ") ) R_2_L = float( input("Please enter the length of Rectangle 2: ") ) R_2_W = float( input("Please enter the weidth of Rectangle 2: ") ) R_1_A = R_1_L * R_1_W R_2_A = R_2_L * R_2_W if R_1_A > R_2_A: print("R 1 is bigger than R 2") elif R_1_A < R_2_A: print("R 2 is bigger than R 1") else: print("R 1 is equal to R 2") Please enter the length of Rectangle 1: Traceback (most recent call last): File "..\Playground\", line 3, in <module> R_1_L = float( input("Please enter the length of Rectangle 1: ") ) ValueError: could not convert string to float:

28th Jun 2019, 8:18 PM
Samad Sunny
Samad Sunny - avatar
1 Answer
+ 5
I've tried your code. It works if you enter four numbers in a row, separated by line breaks. Sample input: 54 32 45 98
28th Jun 2019, 9:14 PM
Anna
Anna - avatar