veronikaaa86

Nested Loops - Python

Feb 12th, 2022 (edited)
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. 01. Clock
  2.  
  3. for h in range(24):
  4. for m in range(60):
  5. print(f"{h}:{m}")
  6.  
  7. ========================================
  8. 02. Multiplication Table
  9.  
  10. for i in range(1, 11):
  11. for j in range(1, 11):
  12. print(f"{i} * {j} = {i * j}")
  13. ================================================================================
  14. 03. Combinations
  15.  
  16. n = int(input())
  17.  
  18. count = 0
  19. for x1 in range (n + 1):
  20. for x2 in range(n + 1):
  21. for x3 in range(n + 1):
  22. sum = x1 + x2 + x3
  23.  
  24. if sum == n:
  25. count += 1
  26.  
  27. print(count)
  28.  
  29. ================================================================================
  30. 04. Sum of Two Numbers
  31.  
  32. start = int(input())
  33. end = int(input())
  34. magic_num = int(input())
  35.  
  36. flag = False
  37. count = 0
  38. for i in range(start, end + 1):
  39. for j in range(start, end + 1):
  40. sum = i + j
  41. count += 1
  42.  
  43. if sum == magic_num:
  44. print(f"Combination N:{count} ({i} + {j} = {sum})")
  45. flag = True
  46. break
  47.  
  48. if flag:
  49. break
  50.  
  51. if not flag:
  52. print(f"{count} combinations - neither equals {magic_num}")
  53.  
  54. ================================================================================
  55. 05. Travelling
  56.  
  57. destination = input()
  58.  
  59. while destination != "End":
  60. price_trip = float(input())
  61.  
  62. sum_current_destination = 0
  63. while sum_current_destination < price_trip:
  64. saved_money = float(input())
  65. sum_current_destination = sum_current_destination + saved_money
  66.  
  67. print(f"Going to {destination}!")
  68.  
  69. destination = input()
  70.  
  71. ================================================================================
  72. 06. Building
  73.  
  74. floors = int(input())
  75. rooms = int(input())
  76.  
  77. #floors = 6
  78. #rooms = 4
  79.  
  80. for f in range(floors, 0, -1):
  81. for r in range(0, rooms):
  82.  
  83. if f == floors:
  84. print(f"L{f}{r}", end=" ")
  85. elif f % 2 == 0:
  86. print(f"O{f}{r}", end=" ")
  87. else:
  88. print(f"A{f}{r}", end=" ")
  89.  
  90. print()
  91.  
Add Comment
Please, Sign In to add comment