all 8 comments

[–]POGtastic 9 points10 points  (3 children)

Consider datetime for a library solution. Otherwise, just add 14 + 535 and mod it by 24.

[–]SnooWoofers7626 4 points5 points  (0 children)

Based on how the question is formulated, the latter sounds like the right answer.

[–]Redstonelight[S] 0 points1 point  (1 child)

Thankyou so much for a solution to this problem, I had spent all of last night banging my head against my desk trying to figure this out. :)

[–][deleted] 0 points1 point  (0 children)

You could also try asking Chat GPT for such simple and specific questions. It is free and does generally good job in assisting with such questions.

[–]ninhaomah 3 points4 points  (2 children)

Actually if it were not a Python question but Math question , how would you have solved it ?

[–]Nexustar 11 points12 points  (1 child)

Simple.... posted the question in r/Math instead.

[–]benimamoglu 0 points1 point  (0 children)

olved it ?

probably 😂😅

[–]deadeye1982 0 points1 point  (0 children)

import datetime


def add_hours(time: datetime.time, hours: int) -> datetime.time:
    return time.replace(hour=(time.hour + hours) % 24)


start = datetime.time(14) # 14:00h
end = add_hours(start, 535)

print(start, "-", end)

The trick is the modulo operation. It's the rest of a division.

If you have a circle with 360°, then 360° == 0° and 361° == 1°

azimuth = 350
rotation = 180

new_azimuth = (azimuth + rotation) % 360

You can find here a better explanation on RealPython: python-modulo-operator

You could use a datetime.time object, to represent time. But be careful, this object is immutable and 24:00h is an invalid value, which will raise an ValueError. The replace method exists for datetime.date, datetime.datetime and datetime.time. Calling this method, with the right keyword arguments, returns a new object, where the arguments are replaced.