Skip to content

Instantly share code, notes, and snippets.

@nitstorm
Created December 31, 2013 19:19
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 nitstorm/8201083 to your computer and use it in GitHub Desktop.
Save nitstorm/8201083 to your computer and use it in GitHub Desktop.
Nested loop example for the blog - http://nitstorm.github.io/blog/
hours = int(input("Please enter number of hours: "))
i = 1
total = 0
#Looping through total number of hours
while i<= hours:
# Setting iterator for minutes
j = 1
# Looping through each minute for current hour
while j <= 60:
#Setting iterator for seconds
k = 1
# Looping through each second for current minute
while k <=60:
# Adding 1 to the value of total number of seconds counted
total = total + 1
k += 1
j += 1
i += 1
print("Total number of seconds in {} hours = {}".format(hours,total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment