-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_and_whileloops_3.py
60 lines (35 loc) · 1.23 KB
/
input_and_whileloops_3.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
# using while with lists and Dictionaries :
# moving items from one list to another :
# Ex :
# users unconfirmed .
unconfirmed_users = ['alice','brian','candace']
confirmed_users=[]
while unconfirmed_users :
current_user=unconfirmed_users.pop()
print(f"\nVerifying user : {current_user.title()}")
confirmed_users.append(current_user)
print("The following users have been confirmed: ")
for confirmed_user in confirmed_users :
print(confirmed_user.title())
# users confirmed .
# note : unconfirmed_users is empty .
# Removing all instancees of specific values from a list :
pets=['dog','cat','dog','goldfish','cat','rabbit','cat']
print(pets)
# removing all 'cat' from the list :
while 'cat' in pets :
pets.remove('cat')
print(pets)
# filling a dictionary with user input :
responses={}
polling_active = True
while polling_active :
name=input("Please enter your name : ")
response=input("Which mountain would you like to climb someday: ")
responses[name]=response
repeat=input("Would you like to let anotehr person respond? (yes/ no) ")
if repeat == 'no' :
polling_active = False
print("--- polling result ---")
for name,response in responses.items() :
print(f"{name.title()} would like to climb {response.title()}")