-
Notifications
You must be signed in to change notification settings - Fork 4
/
assignment_13_1_2022.py
59 lines (43 loc) · 1.63 KB
/
assignment_13_1_2022.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 1. Inside a funtion write a python program that goes through 3 conditional statements until it gets its final output.
def age_check():
age = int(input("Enter your age: "))
if age < 18:
print("You are not old enough to enter this site")
elif age >= 18 and age < 21:
print("You can enter but not drink")
elif age >= 21:
print("You can enter and drink")
else:
print("You are not old enough to enter this site")
age_check()
# 2. create a if statement using the (or)(and) operato
def login_user():
username = input("Enter your username: ")
password = input("Enter your password: ")
if username == "" or password == "":
print("Please enter your username and password")
elif username == "admin" and password == "admin":
print("Welcome admin")
else:
print("Invalid username or password")
login_user()
# 3. Using the user input create a pyramid using the number 1.
def pyramid():
height = int(input("Enter the height of the pyramid: "))
for i in range(height):
print(' ' * (height - i), '1' * (2 * i - 1))
pyramid()
# 4. Create a dictionary and add another item in your dictionary.
def dictionary():
d = {"name": "John", "age": 30, "city": "New York"}
d["nickname"] = "Jane"
print(d)
dictionary()
# 5. Create a dictionary inside a dictionary and use the nesting loop to print your output.
def nested_dictionary():
d = {"name": "John", "age": 30, "city": "New York"}
d["nickname"] = "Jane"
d["address"] = {"street": "Main", "number": "1000"}
for key, value in d.items():
print(key, value)
nested_dictionary()