What is wrong with this? "Python" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is wrong with this? "Python"

#quiz1 quiz1 = "11" if not quiz1.isdigit(): print("Please enter a whole number") quit() #total quiz1 quizTotal1 = "20" #manage whole number if not quizTotal1.isdigit(): print("Please enter a whole number") quit() #if error if quiz1 > quizTotal1: print("Score cannot be greater than total") quit() #compute else: quiz1 = int(quiz1) quizTotal1 = int(quizTotal1) total = (((quizTotal1/quiz1)*100)*.10) print(total) *There will be an output But... #quiz1 quiz1 = "6" if not quiz1.isdigit(): print("Please enter a whole number") quit() #total quiz1 quizTotal1 = "11" #manage whole number if not quizTotal1.isdigit(): print("Please enter a whole number") quit() #if error if quiz1 > quizTotal1: print("Score cannot be greater than total") quit() #compute else: quiz1 = int(quiz1) quizTotal1 = int(quizTotal1) total = (((quizTotal1/quiz1)*100)*.10) print(total) Will give Score cannot be greater than total? Heeeelp.

10th Mar 2021, 6:43 AM
Kakai
Kakai - avatar
5 Answers
+ 3
cause when u compare numeric string, i thnk it will compare ascii value for that first char. so "6" < "11" will return false cause '6' is larger than '1' in ascii
10th Mar 2021, 6:52 AM
durian
durian - avatar
+ 2
Omg, it works. Thank you Lily Mea
10th Mar 2021, 7:34 AM
Kakai
Kakai - avatar
+ 1
try compare int not string eg: int(quiz1) > int(quiztotal1)
10th Mar 2021, 6:50 AM
durian
durian - avatar
0
The only difference are the variable values. first is 11 and 20 going fine... But when i change to 6 and 11. Even the 11 is greater than 6 it shows me score cannot be greater than total. Why?
10th Mar 2021, 6:45 AM
Kakai
Kakai - avatar
0
Hola
12th Mar 2021, 1:43 AM
Ramón cardozo
Ramón cardozo - avatar