forked from aiti-ghana-2012/Lab_Python_04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab4.py
48 lines (45 loc) · 1.15 KB
/
Lab4.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
#1
groceries=['bananas','strawberries','apples','bread']
groceries.append('Champagne')
print groceries
#1b
groceries.remove('bread')
print groceries
#1c
groceries=['bananas','strawberries','apples','bread']
groceries.sort()
print groceries
#2.a. I will use a list.
#2b
store={'Apples':'7.3','Bananas':'5.5','Bread':'1.0','Carrots':'10.0','Champagne':
'20.90','Strawberries':'32.6'}
print store
#2c
store={'Apples':'7.3','Bananas':'5.5','Bread':'1.0','Carrots':'10.0','Champagne':
'20.90','Strawberries':'32.6'}
store['Strawberries']=63.43
print store
#2d
store['Chicken']=6.5
#3a. A list will be best for this because prices of goods are always gonna change.
#3b
in_stock={'Apples':'7.3','Bananas':'5.5','Bread':'1.0','Carrots':'10.0','Champagne':
'20.90','Strawberries':'32.6'}
#Tupple
#3c
always_in_stock=tuple(in_stock)
#3d
print "Come to shoprit! We always sell:"
print always_in_stock,""
#4a.They could use dictionary.
#4b.
def binary_search(lb=0.5,ub=1.5):
while lb<ub:
mid=(lb+ub)/2
midval=a[mid]
if midval<x:
lb=mid+1
elif midval>x:
ub=mid-1
else:
return mid