-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathLists.py
More file actions
110 lines (86 loc) · 2.63 KB
/
Lists.py
File metadata and controls
110 lines (86 loc) · 2.63 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Create a list with “Apples”, “Pears”, “Oranges” and “Peaches”
a = "Apples"
b = "Pears"
c = "Oranges"
d = "Peaches"
fruits = [a, b, c, d]
# Display the list.
print(fruits)
# ask the user for new fruit and add it to end of the list.
print("Please type in a type of fruit")
e = input()
fruits.append(e)
# Display the list.
print(fruits)
# Ask the user for a number
print("Please type in a type number")
num = input()
# display the number and that number's fruit (on a 1-is-first basis).
tada = fruits[int(num) - 1]
print(num, tada)
# Add fruit to the beginning of the list using “+”
fruits2 = ["kiwi"] + fruits
# display the list.
print(fruits2)
# Add fruit to the beginning of the list using insert()
fruits2.insert(0, "pineapple")
# display the list.
print(fruits2)
# Display all the fruits that begin with “P”, using a for loop.
p_fruits = []
for pfruit in fruits2:
if pfruit[0] == "p" or pfruit[0] == "P":
p_fruits.append(pfruit)
print(p_fruits)
# Display the list.
print(fruits2)
# Remove the last fruit from the list.
fruits2.pop(-1)
# Display the list.
print(fruits2)
# Ask the user for a fruit to delete
print(fruits2)
print("Please select a fruit from the list to delete. Your typed response should be case sensitive and match the listed item exactly.")
rotten_fruit = input()
# find it and delete it.
shazaam = []
for find_it in fruits2:
if find_it != rotten_fruit:
shazaam.append(find_it)
print(shazaam)
# (Bonus: Multiply the list times two.
# Keep asking until a match is found.
# Once found, delete all occurrences.)
# Ask user for input "Do you like apples?”
# for each fruit in the list (making the fruit all lowercase).
likes = []
for opinions in fruits2:
print("Do you like " + opinions + "?")
yes_no = input()
str.lower(yes_no)
yes = "yes"
no = "no"
# For any answer that is not “yes” or “no”, prompt user to answer yes or no
if yes_no == yes:
print("Thank you.")
likes.append(opinions)
# For each “no”, delete that fruit from the list.
elif yes_no == no:
print("Okay. We will take that one off the list.")
while yes_no != yes or no:
print("Please answer yes or no.")
break
# Display the list.
print("Please see the fruits you like listed below.")
print(likes)
# Make a copy of the original list
backwards_fruits = fruits[:]
# reverse the letters in each fruit in the copy.
for item in backwards_fruits[:]:
bward_item = item[::-1]
backwards_fruits.append(bward_item)
# Delete the last item of the original list.
fruits.pop(-1)
# Display the original list and the copy.
print(fruits)
print(backwards_fruits)