0

Dubt converting str to float - Why the result is returning as a float if i didnt made the conversion of str to float?

note = int(input("Insert note 1")) note2 = int(input("Insert note 2")) note3 = int(input("Insert note 3")) note4 = int(input("Insert note 4")) average = (note + note2 + note3 + note4) / 4 print ("The notes average is:", average) input ("Press ENTER to exit")

18th Jul 2018, 2:03 PM
André Costa
André Costa - avatar
6 Respostas
+ 5
You use a float division symbol - "/" It automatically converts int to float. If you want to have an integer division, you should use the "//" symbol, a floor division (rounds down to the next smallest integer).
18th Jul 2018, 2:07 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
André Costa Depends on you, actually. You can keep it a float, so it's closer to the actual mathematical truth, but you can display it "pretty" with adequate string formatting :)
18th Jul 2018, 2:17 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Kuba Siekierzyński average = int((note1+note2+note3+note4)/4)
18th Jul 2018, 2:10 PM
RainStorm
RainStorm - avatar
+ 2
張皓雨 Indeed.
18th Jul 2018, 2:13 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Many Thanks guys =) awasome comunity
18th Jul 2018, 2:19 PM
André Costa
André Costa - avatar
0
Kuba Siekierzyński but to make the program prettier and more correct should we place float instead of int right? thanks =)
18th Jul 2018, 2:13 PM
André Costa
André Costa - avatar