Doing an Uni grade calculator but i have an specific error with an operator on python + Some questions on return functions

Viewed 34

every time i run it all the inputs run flawlessly but when i go to my first calculation the program runs it but then i hit the wall with this error and i think i will hit it on the others and i dont know how to fix it + im trying to return the results to the annoounced variables VSC says return mus be inside of a function this is the error i get:

Traceback (most recent call last):
  File "c:\Users\santi\OneDrive\Imágenes\Documentos\prog\Notas.py", line 29, in <module>
    print(((RP1+RP2+CI1)/3)+BN1)*(P1)*(PC)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
from ast import Break   
#Translate from spanish to english for you to understand
print('Bienvenido a la calculadora de promedio las notas son entre 0.0 y 5.0!')# Welcome to the Grade Calculator remember all grades go from 0.0 to 5.0!       
RP1 = float(input("Diijte la nota del primer reto de programación")) # input your 1st programming challenge grade
RP2 = float(input("Dijite la nota del Segundo reto de programación")) # input your 2nd programming challenge grade
CI1 = float(input("Dijite la nota del Comentario")) # input your 1sr Engineering comment
RP3 = float(input("Dijite la nota del tercer reto de programación")) #input your 3rd programming challenge grade
RP4 = float(input("Dijite la nota del cuarto reto de programación")) #input your 4th programming challenge grade
CI2 = float(input("Dijite la nota del comentario N#o2: ")) #input your 2nd Engineering comment
RP5 = float(input("Dijite la nota del quinto reto de programación")) # input your 6th programming challenge grade
RP6 = float(input("Dijite la nota del sexto reto de programación")) # input your 7th programming challenge grade
CI3 = float(input("Dijite la nota del Comentario final")) # input your Final Engineering comment
BN1= float(0.1) # this means 1 tenth bonus to the overall grade
BN2= float(0.2) # this means 2 tenths bonus to the overall grade can only be used only from the 3ns cut and above
P1= float(0.3) # this means the 1st cut or 30% of the overall grade
P2= float(0.3) # this means the 2nd cut or 30% of the overall grade
P3= float(0.4) # this means the 3rd cut or 40% of the overall grade
PC= float(100) #This one means 100%
CN1 = float(0.0) # this means the overall Cut 1 grade returned to this variable
CN2 = float(0.0) # this means the overall Cut 2 grade returned to this variable
CN3 = float(0.0) #this means the overall Cut 3 grade returned to this variable
N = str(input("Hola usuario! Dijite C1 si quiere las notas del primer corte, C2 si quiere las notas del Segundo corte, C3 si quiere las notas del tercer corte u F si quiere la nota final"))
 # "Hello user! input C1 if you want the notes of the first cut, C2 if you want the notes of the second cut, C3 if you want the notes of the third cut or F if you want the final grade."
while True:

    
    if N == 'C1':
        print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP1, RP2,CI1,BN1,P1,PC))
    print(((RP1+RP2+CI1)/3)+BN1)*(P1)*(PC) 
    break

while True:
    
    if N== 'C2':
     print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP3, RP4,CI2,BN1,BN2,P2,PC))
    print(((RP3+RP4+CI2)/3)+BN1+BN2)*(P2)*(PC) 
    break

while True:
    
    if N== 'C3':
     print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP5, RP6,CI3,BN1,BN2,P3,PC))
    print(((+RP6+CI3)/3)+BN1+BN2)*(P3)*(PC) 
    break

while True:
    
    if N== 'F':
     print('{} + {} + {} / 3 + {}+ {} * {} = '.format(CN1,CN2,CN3,P3,PC))
    print(((CN1+CN2+CN3)/3))*(P3)*(PC)
    break

Short part where the Code Breaks:

python

Test1 = float(input('test number between 0.0 and 5.0'))
Test2 = float(input('test number between 0.0 and 5.0'))  
Tst3 = float(input('test number between 0.0 and 5.0'))  
PC = int(100)   
RT= float(0.0)
print('{} + {} + {} / 3 = '.format(Test1,Test2,Tst3))      
print(((Test1+Test2+Tst3)/3))*(PC)
1 Answers

you just forgot to add the print brackets so instead of

print(((RP1+RP2+CI1)/3)+BN1)*(P1)*(PC) 

add brackets on the whole thing after the print -> print(here put what you want to print)

so it will be like this

print( (((RP1+RP2+CI1)/3)+BN1)*(P1)*(PC) )

notice the number of brackets

and other note:

you don't need the while loops here because you want to check every case just once so just use if statements like so (and also the print wasn't indented so it would've printed all the print functions no matter the case):

if N == 'C1':
    print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP1, RP2,CI1,BN1,P1,PC))
    print( (((RP1+RP2+CI1)/3)+BN1)*(P1)*(PC) )


if N== 'C2':
    print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP3, RP4,CI2,BN1,BN2,P2,PC))
    print( (((RP3+RP4+CI2)/3)+BN1+BN2)*(P2)*(PC) ) 


if N== 'C3':
    print('{} + {} + {} / 3 + {}+ {} * {} = '.format(RP5, RP6,CI3,BN1,BN2,P3,PC))
    print( (((+RP6+CI3)/3)+BN1+BN2)*(P3)*(PC) )


if N== 'F':
    print('{} + {} + {} / 3 + {}+ {} * {} = '.format(CN1,CN2,CN3,P3,PC))
    print( (((CN1+CN2+CN3)/3))*(P3)*(PC) )

another note: this is not necessary but to avoid problems from user input add a space at the end of the text that will be displayed for input, so the user wont add a space and it will be considered part of the input. this wont be a problem with the float input but it will be a problem with the string input so instead of:

N = str(input("Hola usuario! Dijite C1 si quiere las notas del primer corte, C2 si quiere las notas del Segundo corte, C3 si quiere las notas del tercer corte u F si quiere la nota final"))

make it:

N = str(input("Hola usuario! Dijite C1 si quiere las notas del primer corte, C2 si quiere las notas del Segundo corte, C3 si quiere las notas del tercer corte u F si quiere la nota final: "))
Related