# Help in fixing this code

#### 2s3d23

Hello all first of all, nice forum.
I just joined today! In hopes to find some help to my coding errors, because I just started to learn python and I like it so far.
So I'm going directly to the matter. I'll first post what's the code expected to do and then what I have done so far.
Note the code worked fine but wasnt fully functional and now it seems a bit more broken as I tried to polish it against wrong typing from a potential user.

This code pretends to first fetch a number of students or a number of califications to be more precise, then proceeds to ask for the calification grade each time until reaching the number first specified in the code, and also does catch the lowest and highest grade of those entered, it also makes an average of the grades.

Sorry for the broken language, I'm not native. Please have some patience with me.

I have something like this:

Python:
``````def read_int():
while True:
try:
x = 0
students = int(input("Enter the number of students to evaluate: "))
counter = 0
while x < students :
try:
counter = counter + 1
students = students - 1
x = x + 1
break
else:
while True:
try:
average = round(sum_grades / counter, 1)
print("The average is ", average )
break
except ValueError:
print("")
except ValueError:
print("")
except ValueError:
print("")

#### phillip1882

Python:
``````def read_int():
while True:
try:
x = 0
students = int(input("Enter the number of students to evaluate: "))
except ValueError:
print("The number of students must be an integer")
continue
counter = 0
while x < students :
while True:
try:
except ValueError:
print("only integers and floats")
continue
print("only values between 1 and 7")
continue
break
counter = counter + 1
x = x + 1
average = round(sum_grades / counter, 1)
print("The average is ", average )
check =input("would you like to grade more students? Y/N ")
if check == "Y":
pass
else:
break``````
here's my fixes.

#### 2s3d23

Thanks for the reply but when run the code gives me:
Process finished with exit code 0

#### 2s3d23

So apparently I made it. Many thanks to phillip1882 for his will to help me anyway.
This code asks for input to get how many grades are to be reviewed, after which proceeds to gather such grades one by one, string error proof, and within a valid range for grades from 1 to 7 (califications system for native country), to then calculate the highest and lowest grade from the entered lot, aswell as the average of all grades for that round, to end asking either for further input to keep on reviewing grades or if the user wants to finish altogether.
Please note the language is not English, by the way.
Python:
``````def read_float():
x = 0
while x == 0:
try:
lista = []
try:
while notas > 7 or notas < 1:
print("Por favor, ingrese notas válidas.")
break
else:
if 1 <= notas <= 7:
lista.append(notas)
except ValueError:
print("Por favor, ingrese un valor numérico...")
print("")
continue
print(f"Las notas ingresadas secuencialmente fueron: {lista}")
print("La nota más alta es:", max(lista))
print("La nota más baja es:", min(lista))
suma = sum(lista)
promedio = round(suma / len(lista), 1)
print(f"El promedio es: {promedio}")
x += 1
while x == 1:
try:
seguir = int(input("\n"
"¿Desea continuar evaluando notas?\n"
"1.- Sí.\n"
"2.- No.\n"
":"))
if seguir == 2:
"")
x += 1
break
elif seguir == 1:
x -= 1
print()
pass
else:
if seguir != 1 or seguir != 2:
print("Por favor, ingrese una opción válida.")
except ValueError:
print("Por favor, ingrese una opción válida.")
print("")
except ValueError:
print("Por favor, ingrese un valor entero.")
print("")

Last edited:

#### phillip1882

you need to add read_int() to the bottom of the code. let me know if that doesn't fix it.

#### phillip1882

so my code does all that.
you just need to add read_int() to the bottom of the code.

#### phillip1882

your second code post is in much the same manner as your first. go over my code answer and copy as much as you can.
in particular your try except blocks should be handled better.

#### 2s3d23

Well it works but not as I was expected it to be, for example, after the first prompt is passed, every time a grade is put in, it instantly do the calculations and shows the average, highest and lowest grades, I did a run and choose to input 4 grades and it stopped to the second one after trying the other values, by entering numbers out of range or by sending blank input, also when asked if you want to continue reviewing grades, you can just press any input and it will finish anyhow, so it's not fully error proof against typos that might stop your code fully. But thanks for your good will, I hope you can help me in the future If I'm lost to find a solution for a code project, so your help will always be appreciated.