-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquess_number_while_loop.py
More file actions
44 lines (37 loc) · 1.45 KB
/
quess_number_while_loop.py
File metadata and controls
44 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Use the 'while loop' and 'if' statement to write the magician game.
secret_number = 777
print(
"""
+================================+
| Welcome to my game, muggle! |
| Enter an integer number |
| and guess what number I've |
| picked for you. |
| So, what is the secret number? |
+================================+
""")
guess_number = int(input("Enter a number: "))
while guess_number:
if guess_number == secret_number:
print("Well done, muggle! You are free now.")
break
else:
print("Ha ha! You're stuck in my loop!")
guess_number = int(input("Enter a number: "))
# PYRAMID BLOCKS
# A pyramid is stacked according to one simple principle: each lower layer contains one block more than the layer above.
# Your task is to write a program which reads the number of blocks the builders have, and outputs
# the height of the pyramid that can be built using these blocks.
# height of the pyramid is measured by the number of fully completed layers –
# if the builders don't have a sufficient number of blocks and cannot complete the next layer, they finish their work immediately.
blocks = int(input("Enter the number of blocks: "))
#
# Write your code here.
try:
for level in range(1, blocks+1):
if blocks >= level:
height = level
blocks -= level
print("The height of the pyramid:", height)
except Exception as e:
print("You have zero blocks", e)