Python Forum
Logic of using floor division and modulus for a different variable at different time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logic of using floor division and modulus for a different variable at different time
#1
Hi,

In the below code(Code_1), please help me understand the logic of dividing minutes and seconds by 10. The second program(Code_2) also gives the same result. But the below program's logic, I'm unable to understand.

Code_1
seconds=eval(input("Please enter the number of seconds: "))
hours=seconds//3600
seconds=seconds%3600
minutes=seconds//60
seconds=seconds%60
print(hours, ":", sep="", end="")
tens=minutes//10
ones=minutes%10
print(tens, ones, ":", sep="", end="")
tens=seconds//10
ones=seconds%10
print(tens, ones, sep="")

Code_2
seconds=eval(input("Please enter the number of seconds: "))
hours=seconds//3600
seconds=seconds%3600
minutes=seconds//60
seconds=seconds%60
print(hours,":",minutes,":",seconds)
Reply


Messages In This Thread
Logic of using floor division and modulus for a different variable at different time - by SB_J - Nov-01-2018, 07:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cmath.rect accepts a negative modulus JMB 2 365 Jan-17-2024, 08:00 PM
Last Post: JMB
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 1,337 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  Division questions Dionysis 5 1,102 Feb-14-2023, 02:02 PM
Last Post: Dionysis
  Floor approximation problem in algorithm gradlon93 3 994 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  Division by zero and value of argument Lawu 5 3,207 Jul-01-2022, 02:28 PM
Last Post: Lawu
  Floor division problem with plotting x-axis tick labels Mark17 5 2,157 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Division calcuation with answers to 1decimal place. sik 3 2,156 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 4,073 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 3,100 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Floor division return value Chirumer 8 3,851 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020