-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeeting_notes.py
More file actions
216 lines (212 loc) · 5.39 KB
/
Copy pathmeeting_notes.py
File metadata and controls
216 lines (212 loc) · 5.39 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Basic syntax: variables, data types, input, and output.
# Control Flow: if, else, elif ,,, while, for loops
# Functions
# Lists
# Dictionaries
# Tuples
# Sets
#//////////////////////////
#difference between c++ and python, python is interpreted language, c++ is compiled language
#//////////////////////////
#exmaples of basic syntax
boolean = True
integer = 1
floating_point = 1.0
string = "Hello World"
character = 'a'
#//////////////////////////
#examples of input and output
#input
name=input("Enter your name: ")
#output
print("Hello",name)
#//////////////////////////
#examples of control flow
if boolean:
print("This is true")
else:
print("This is false")
#short-handed if statement:
print("true") if boolean else print("false")
while integer < 10:
print(integer)
integer += 1
for i in range(10):
print(i)
#//////////////////////////
#examples of functions
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def recursive_function_factorial(n):
if n == 1:
return 1
else:
return n * recursive_function_factorial(n - 1)
#//
#built in functions
#//
#len
#len only works for array and string
#len doesnt work with any numiric variable
x=675
y='ABCD'
z=[3,4,'abc']
print('length of y= ',len(y),'length of z= ',len(z))
#//
#type
#type returns the type of the variable
print(type(x))
print(type(y))
print(type(z))
#//
#input
#input takes input from the user
#input always returns a string
#so if you want to take input as an integer
#you have to convert it to an integer
#using int()
#or you can take input as a float
#using float()
#or you can take input as a boolean
#using bool()
#or you can take input as a string
#using str()
#//
#output
#output is done using print()
#sort
#//////////////////////////
#examples of lists
list1 = [1, 2, 3, 4, 5]
list2 = [1, "Hello", 3.0, True]
list3 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
list4=[]
list4.append(1)
list4.insert(0,2)
list2.remove("hello")
list2.remove("Hello")
list2.pop(0)
length=len(list2)
sublist=list2[0:2]
#list comprehension
list5=[i for i in range(10)]
#2D list initialization
li=[[_ for _ in range(5)] for _ in range(6)]
li2=[[0]*5]*6
for i in range(6):
for j in range(5):
li[i][j]=1
li2[i][j]=j+1
print(li)
print(li2)
#//////////////////////////
#examples of dictionaries
dict1 = {"key1": 1, "key2": 2, "key3": 3}
dict2 = {"key1": 1, "key2": "Hello", "key3": 3.0}
dict3 = {"key1": [1, 2, 3], "key2": [4, 5, 6], "key3": [7, 8, 9]}
dict4={}
dict4["key1"]=1
dict1["key2"]=44
dict4["key3"]=3
poped_item=dict4.pop("key1")
del dict4["key3"]
keys=dict1.keys()
values=dict1.values()
items=dict1.items()
#//////////////////////////
#examples of tuples
#note tuples are immutable once created you cant change them
tuple1 = (1, 2, 3, 4, 5)
tuple2 = (1, "Hello", 3.0, True)
tuple3 = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
tuple4=(1,2,3)
tuple4=tuple4+(4,)
lenght=len(tuple4)
subtuple=tuple4[0:2]
#//////////////////////////
#examples of sets
#--
#note sets are unordered and unindexed
#--
#difference between sets and
#lists is that sets don't allow duplicates
#--
#difference between sets and dictionaries
# is that sets don't have keys
#--
set1 = {1, 2, 3, 4, 5}
set2 = {1, "Hello", 3.0, True}
set3 = {(1, 2, 3), (4, 5, 6), (7, 8, 9)}
set4=set()
set4.add(1)
set4.add(2)
set4.add(3)
#the update method can be used to add multiple
#items to a set
set4.update([4,5,6])
set4.remove(1)
set4.discard(2)
#difference between remove and discard is that remove will
# throw an error if the item doesn't exist in the set
poped_item_set=set4.pop()
union_set=set1.union(set4)
intersection_set=set1.intersection(set4)
difference_set=set1.difference(set4)
#//////////////////////////
#final project
def main():
phone_record={}
while True:
print('''1. Add a new phone number
2. Delete a phone number
3. Update a phone number
4. Search a phone number
5. Display all phone numbers
6. Quit''')
choice=int(input('Enter your choice: '))
if choice ==6:
break
elif choice==1:
add_contact(input('Enter name: '),input('Enter number: '),phone_record)
elif choice==2:
delete_contact(input('Enter name: '),phone_record)
elif choice==3:
update_contact(input('Enter name: '),input('Enter number: '),phone_record)
elif choice==4:
search_contact(input('Enter name: '),phone_record)
elif choice==5:
display_all(phone_record)
else:
print('Invalid choice')
def add_contact(name,number,phone_record):
if (name in phone_record):
print('Contact already exists with this name')
else:
phone_record[name]=number
print('Contact added successfully')
def delete_contact(name,phone_record):
if name in phone_record:
del phone_record[name]
print('Contact deleted successfully')
else:
print('Contact not found')
def update_contact(name,number,phone_record):
if name in phone_record:
phone_record[name]=number
print('Contact updated successfully')
else:
print('Contact not found')
def search_contact(name,phone_record):
if name in phone_record:
print('Contact found')
print('Name: ',name,'Number: ',phone_record[name])
else:
print('Contact not found')
def display_all(phone_record):
for name,number in phone_record.items():
print('Name: ',name,'Number: ',number)
if __name__=='__main__':
main()
#//////////////////////////