-3
Hours= int(input("What Hour is it?"))
Minutes= int(input("What Minute is it?"))
if Hours<12:
    print(Hours , (':'), Minutes)
elif Hours>12:
    print(Hours-12 ,(':'), Minutes)

I'm trying to make the following code go to the closest quarter/15 minutes but don't know how. Any help would be appreciated

Anand S Kumar
  • 82,977
  • 18
  • 174
  • 164
jamesonr
  • 41
  • 1
  • 5

2 Answers2

0

try rouning you minutes to 15:

Hours= int(input("What Hour is it?"))
Minutes= int(input("What Minute is it?"))
if Hours<12:
    print(Hours , (':'), Minutes)
elif Hours>12:
    print(Hours-12 ,(':'), Minutes)
Minutes= round(Minutes/15)*15
user 12321
  • 2,658
  • 1
  • 22
  • 34
0

Please check your solution if you are not change minute variable then how u can expect that it set to the nearest quater. SO you just need to add 1 line which alter minute
for getting answer like 1st quater,2nd quater,3rd quater or 4th quater :

minute = (minute+1)%15


for getting answer like 15min,30min,45min,60min :

minute = ((minute+1)%15)*15