CS50 Python , Nutrition Facts Table
If you're taking PCAP - Programming Essentials In Python , you may have encountered this question in 2.6.1.11 LAB: Operators and expressions asking you for a code to evaluate end time. It goes like this:
new_mins = mins + dura # Add a new variable for minutes to add the input minutes to the existing ones (mins = 17 . dura = 59. new_mins = 17+59 = 76)
new_hours = new_mins // 60 # Add a new variable for the new hours. // 60 means to get how many hours (rounded) in the new given minutes (76 // 60 = 1)
final_hours = new_hours + hour # Add a new variable to get the result needed for the hours. It's an addition process to add the input hour (12) + the new hours rounded (1) will be (13)
final_minutes = new_mins % 60 #Add a new variable to get the result needed for the minutes. It's an addition process to get the remainder of the new minutes (76) which is (16). Why 16? one hour = 60 minutes. 76 - 60 (this's called remainder %) = 16
Comments
Post a Comment
Your opinion matters, your voice makes us proud and happy. Your words are our motivation.