Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Question 1
- def input_shopping_list():
- shoppingList= list()
- item = input("Enter an item: ")
- while item != "done":
- shoppingList.append(item)
- item = input("Enter an item: ")
- return shoppingList;
- shoppingList = input_shopping_list()
- count = 0
- print("\n")
- for i in shoppingList:
- print(i)
- count = count + 1
- print("Total items on shopping list: " + str(count))
- # Question 2
- p=[1,2,3]
- q=['a', 1, 'b', 3]
- def find_common_elements(list_p, list_q):
- common_list = []
- for num in list_p:
- if num in list_q and num not in common_list:
- common_list.append(num)
- return common_list
- print(find_common_elements(p,q))
- #Question 3
- def linearSearch(t, v):
- i = 0
- index = -1
- while i < len(t):
- if t[i] == v:
- index = i
- break
- i += 1
- return index
- print(linearSearch('egg', 'e'))
- print(linearSearch('egg', 'v'))
- print(linearSearch([1, 3, 2, 5], 2))
- print(linearSearch([1, 3, 2, 5], 6))
- #Question 4
- pets = {
- "Hammond": "dog",
- "Mike": "fish",
- "Hunter": "zebra"
- }
- for name, animal_type in pets.items():
- print(name + " is a " + animal_type + ".")
- #Question 5
- s = input("Enter a string:")
- d = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
- for letter in s:
- if letter in d:
- d[letter] += 1
- for key in d:
- print("There are", d[key], "instances of", key, "in", s)
- #Question 6
- inventory = {'gold': 150,
- 'pouch' : ['flint', 'twine', 'lucky charm'],
- 'backpack' : ['knife', 'bedroll', 'jerky']}
- inventory['pocket'] = ['pebble', 'large chestnut', 'lint']
- inventory['backpack'].sort()
- inventory['backpack'][1] = 'crackers'
- inventory['gold'] += 25
- print(inventory)
- #Question 7
- d={}
- d['Darci Lynne'] = 0
- d['Angelica Hale'] = 0
- d['Angelina Green'] = 0
- while True:
- name = input('Enter contestant name:')
- if name == 'done' or name=='Done':
- break
- else:
- if name in d.keys():
- d[name] = d[name] + 1
- else:
- d[name] = 0
- for i in d.keys():
- print(i,'',d[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement