-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chap3.py
65 lines (52 loc) · 1.71 KB
/
Chap3.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def invitations(guests):
txt = 'Hi %s:\nYou are invited to a dinner party at the beach\nHappy summers\n\n'
for x in guests:
print(txt % (x))
return
# 3-4 Guest List
print('3-4')
guests = ['Ahmed', 'Rehan', 'Zeeshan']
#3-9(Length of the list)
print("Number of Guests invited: "+str(len(guests)))
invitations(guests)
# 3-5 Changing guest list
# lets say Ahmed is not comming to the party
print('3-5')
removedGuest = 'Ahmed'
guests.remove(removedGuest)
print('Sorry %s couldnt make it to the party\n\n' % removedGuest)
guests.insert(0,"Khan")#added new guest
invitations(guests)
# 3-6 Changing guest list
# Found a bigger table
print('3-6')
guests.insert(0,"Shahzad")#added new guest at the top
guests.insert(2,"Zain")#added new guest in the middle
guests.append("Ali")#added new guest at the end
invitations(guests)
# 3-6 Changing guest list
# Reducing the list
print('3-7')
#reduces list to 2
while len(guests)>2:
guests.pop()
invitations(guests)
#removing the rest 2 invitees
del guests[1]
del guests[0]
#printed emptied list
print('Emptied List '+str(guests)+"\n\n\n\n")
#3-8
#unsorted raw list
destinations=["Paris","Karachi","Kathmandu","Seychelles","Maldives"]
print("Unsorted Destinations: " + str(destinations))#raw List
print("Sorted Destinations: "+str(sorted(destinations)))#Alphabatical Order
destinations.reverse()
print("Reversed: "+str(destinations))#unorderd reverse
destinations.reverse()
print("Reversed Again: "+str(destinations))#unorderd reverse again
destinations=sorted(destinations)
print("Reversed and Assigned: "+str(destinations))#unorderd reverse again
destinations.reverse()
destinations=sorted(destinations,reverse=True)
print("Reverse Sorted: "+str(destinations))#unorderd reverse again