-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhile_3.py
More file actions
66 lines (62 loc) · 3 KB
/
while_3.py
File metadata and controls
66 lines (62 loc) · 3 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Начинаем с двух списков: пользователей для проверки
# и пустого списка для хранения проверенных пользователей.
unconfirmed_users = ['alice', 'brian', 'candace']
confirmed_users = []
# Проверяем каждого пользователя, пока остаются непроверенные
# пользователи. Каждый пользователь, прошедший проверку,
# перемещается в список проверенных.
while unconfirmed_users:
curent_user = unconfirmed_users.pop()
print("Verified users " + curent_user.title())
confirmed_users.append(curent_user)
print("\nThe following users have been confirmed: ")
for confirmed_user in confirmed_users:
print(confirmed_user)
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)
responses = {}
# Установка флага продолжения опроса.
polling_active = True
while polling_active:
# Запрос имени и ответа пользователя.
name = input("\nWhat is your name? ")
response = input("Which mountain would you like to climb someday? ")
# Ответ сохраняется в словаре:
responses[name] = response
# Проверка продолжения опроса.Использование цикла while со списками и словарями 133
repeat = input("Would you like to let another person respond? (yes/ no) ")
if repeat == 'no':
polling_active = False
# Опрос завершен, вывести результаты.
print("\n--- Poll Results ---")
for name, response in responses.items():
print(name + " would like to climb " + response + ".")
sandwich_order = ['bacon', 'chicken', 'pork', 'fish', 'pastrami', 'pastrami', 'pastrami']
finished_sandwich = []
print("\nI made your tuna sandwich" + str(sandwich_order))
print("pastrami is not defined")
while 'pastrami' in sandwich_order:
sandwich_order.remove('pastrami')
print(sandwich_order)
while sandwich_order:
sandwich = sandwich_order.pop()
finished_sandwich.append(sandwich)
print("All sandwiches is finished " + str(finished_sandwich))
dream_travels = {}
polling_active = True
while polling_active:
#запрос имени и ответа пользователя
name = input("\nWhat is youre name? ")
responses = input("What youre favorite country ")
# Ответ сохраняется в словаре:
dream_travels[name] = response
# Проверка продолжения опроса.Использование цикла while со списками и словарями 133
repeat = input("Would you like to let another person respond? (yes/ no) ")
if repeat == 'no':
polling_active = False
print("\n--- Poll Results ---")
for name, dream_travel in dream_travels.items():
print(name + " favorite country is : " + dream_travel)