+ 1

Code Coach: How Many Miles?

I’m doing the first code coach for Python 5.1. It asks: Calculate and output the number of miles in 1000 kilometers. Hint One mile is 1.6 kilometers, so find the quotient of 1000 and 1.6. I looked at my calculator beforehand and saw that 1000/1.6 is 625.0, no remainders, so why is it wrong when i do print(1000/1.6) and it displays 625.0, but right when i do print(1000//1.6) and it displays 624.0 when it’s mathematically wrong?

28th Dec 2021, 11:04 PM
James Nguyen
James Nguyen - avatar
3 Réponses
0
print(1000/1.6-1) # This answer also works, fooling the program asking to use "//" jaja It seems that you are right, so curious... https://www.wolframalpha.com/input/?i=1000%2F1.6+is+an+integer%3F
29th Dec 2021, 1:17 AM
CGM
CGM - avatar
0
Hi James Nguyen , Because integer / float is float And because the result will be float, // rounds it down so 265.0 becomes 264.0
29th Dec 2021, 8:10 PM
SoloilSole
SoloilSole - avatar
0
#your code goes here x=1000 y=1.6 print (x//y)
26th Sep 2022, 5:19 PM
Pusparasa Ayilavan
Pusparasa Ayilavan - avatar