1. GPS Write a Python program that estimates the number of blocks to travel from
ID: 3620233 • Letter: 1
Question
1. GPSWrite a Python program that estimates the number of blocks to travel from one address to another
along the same street. Your algorithm should assume that addresses are numbered using a Vancouver
numbering scheme, that is, numbers always increase in the same direction, and that each block goes
up by 100.
Please input your starting address: 2356
Please input your destination address: 6889
You have roughly 45 blocks remaining.
Please input your starting address: 5715
Please input your destination address: 3884
You have roughly 18 blocks remaining.
You will ?nd useful the built-in function abs(x) which calculates the absolute value of the number x.
2. Digital Clock Readout
Write a Python program that displays a time in HH:MM format. The user will be prompted for a
number of minutes, an integer not less than 60. The output will match the corresponding time in hours
and minutes, as shown in the samples below.
Please input the number of minutes (not less than 60): 80
The time is 1:20.
Please input the number of minutes (not less than 60): 630
The time is 10:30.
To solve this problem, you will use Python’s % operator, which, in the Python expression a % b, ?nds
the remainder when the integer a is divided by b. E.g. The expression 630 % 60 results in 30.
Explanation / Answer
Dear...2.
def GetInHMS(seconds):
hours = seconds / 3600
seconds -= 3600*hours
minutes = seconds / 60
seconds -= 60*minutes
if hours == 0:
return "%02d:%02d" % (minutes, seconds)
return "%02d:%02d:%02d" % (hours, minutes, seconds)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.