Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 2
How do I convert the str to int without an error
def grading(): if student_score <40: print("Grade: F") elif student_score <46: print("Grade: E") elif student_score <50: print("Grade: D") elif student_score <60: print("Grade: C") elif student_score <70: print("Grade: B") elif student_score >70: print("Grade: A") student_score=int(input("Enter the student score or enter to exist")) total_score=0 number_of_students=0 grading() while student_score != "": total_score+= student_score number_of_students+=1 student_score=int(input("Enter the student_score or enter to exist")) grading () print("number of students =",number_of_students) average= total_score / number_of_students print("Average=",average)
11 Answers
+ 3
Doesn't this do what you want?
https://code.sololearn.com/c58VoL8eadrW/?ref=app
+ 3
You're closing the while loop when the input is "" (nothing), but you try and cast the input to int before checking that there is anything in the string.
score = input()
while score != "":
score = int(score)
# do_stuff
score = input()
+ 2
I think you might have done this.
Still, you can see the following code:-
s=int(input())
print(s)
+ 1
You get invalid literal error, when the input isn't an integer.
In your while loop, you are comparing student_score with a string and it isn't a string...
+ 1
AKSHAY I know. I am currently using pydroid3
+ 1
Guys help I still can't correct the error anyone to help
+ 1
Russ thanks very much it runs just fine..I will compare it to mine and make the necessary adjustments. Thanks
0
Yeah I did that it keeps telling me
ValueError: invalid literal for int() with base 10: ''
0
Adeniran not sure but I think this may be due sololearn input problem as your program needs more than 1 input and it requires all input to be given in starting at time of running, if you are not giving proper input then it will cause error..
- 1
Hi
- 2
Use type casting property
Example:-
Store="58"
restore=int(store)
print(restore)