Click here to Skip to main content
15,071,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone , Please can you explain to me why the terminal print the variable mean like a float knowing that i didn't define it like a float
Python
counter = 0
Sum = 0

while counter < 5:
	Mark = int(input("Enter the mark M{} = ".format(counter+1)))
	counter += 1
	Sum = Sum + Mark

Mean = Sum / 5 

print("the sum is : ",Sum)
print("The mean is : ",Mean)


What I have tried:

Coding on the text editor and searching on the net
Posted
Updated 13-Oct-21 10:07am
Comments
Member 15329613 13-Oct-21 16:04pm
   
What do the print statements print?

1 solution

Python does dynamic typing - there is no way to statically type a variable. When you do Mean = Sum / 5 Python computes this in floating point for you. You can force integer division using the // operator. Note that this does not round to the nearest multiple so 17 // 3 evaluates to 5, not 6. To get the remainder use the modulus operator %
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900