In Python 2, input
returns a Python object interpreted according to the syntax of that language (ie if you type "2", it returns the number 2
). In Python 3, it simply returns a string (the same as raw_input
" of Python 2, if I'm not mistaken).
In this way, when adding the values of n1
to n4
you are actually concatenating strings, not a sum of numbers:
float ((n1 + n2 + n3 + n4)) / int(4)
= float('2' + '2' + '2' + '2') / 4
= float('2222') / 4
= 2222/4
= 555.5
To get the result you want, convert each individual variable to a number:
n1 = float( input ("informe sua nota do 1º Bimestre ") )
n2 = float( input ("informe sua nota do 2º Bimestre ") )
n3 = float( input ("informe sua nota do 3º Bimestre ") )
n4 = float( input ("informe sua nota do 4º Bimestre ") )
media = (n1 + n2 + n3 + n4) / 4