Skip to content

Instantly share code, notes, and snippets.

@kendhia
Last active October 13, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendhia/5e95f6c5d650ca0f01b0755f06d7e335 to your computer and use it in GitHub Desktop.
Save kendhia/5e95f6c5d650ca0f01b0755f06d7e335 to your computer and use it in GitHub Desktop.
python_is_very_easy_to_learn_:)
input_saat = int(input("saat : "))
input_dk = int(input("dakika : "))
var_ekle = int(input("ekle : "))
#instead of using constant numbers inside the code it is a good habit to declare a final constant and use it in the wole code.
#if you didn't understand this just skip it it's not a big deal for now ;=)
MIN_IN_HOUR = 60
HOUR_IN_DAY = 24
#that's the easiset step i'm sure you understand it
new_min = input_dk + var_ekle
#but as you know the user may add a big number that will pass 60min so we should take
#the mod by 60 to ensure we're displaying the right minuts
min_to_display = (new_min)%MIN_IN_HOUR
#and we take the additional hours (if any) to add to our currrent hour
#ex : 24 min + 40 min = 62 min => min_to_dsiplay = 2 and hour_from_min = 1
hour_from_min = (new_min)//MIN_IN_HOUR
#our new hour
new_saat = input_saat + hour_from_min
#but as you know the hour also may be more than 24h, so we should just take
#the mod by 24 and everything is right.
hours_to_display = new_saat%HOUR_IN_DAY
#you have what you need now
print("now the hour is : " + str(hours_to_display) + ":" + str(min_to_display))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment