-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearnpython.py
More file actions
351 lines (268 loc) · 9.95 KB
/
Copy pathlearnpython.py
File metadata and controls
351 lines (268 loc) · 9.95 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# basic string concat
#my_goal = "ace the exam"
#subject = "I am gonna "
#sentence = subject + my_goal
#print(sentence)
# ints
# age = 21
# age += 1
# print("i am " + str(age))
# floats
# height = 169.9
# print("my height is " + str(height))
# boolean data
# human = True
# print("i am a human: " + str(human))
#multiple assignment
#name, age, attractive = "supun", 22, True
#print(name)
#print(age)
#print(attractive)
# password
# password = "admin"
# input_password = input("enter password \n")
# if input_password.lower() == password:
# print("Welcome")
# else:
# print("try again")
# string methods
# characters = "supun"
# print(len(characters))
# print(characters.capitalize())
# print(characters.upper())
# print(characters.lower())
# print(characters.isdigit())
# print(characters.find("p"))
# print(characters.count("u"))
# print(characters.replace("u", "e"))
# print(characters*6)
# string indexing
# name = "supun seth xiii"
# first_name = name[0:5]
# middle_name = name[6:10]
# last_name = name[11:]
# wtf_name = name[2:11:2]
# reversed_name = name[::-1]
# print(first_name)
# print(middle_name)
# print(last_name)
# print(wtf_name)
# print(reversed_name)
# string slicing
# website_1 = "https://google.com"
# website_2 = "https://dod.gov"
# domain_name = slice(8, -4) #this will create a SLICE OBJECT!!!
# print(website_1[domain_name])
# print(website_2[domain_name])
# math module
# import math
# pi = 3.14
# x = 1
# y = 2
# z = 6
# print(pi)
# print(round(pi))
# print(abs(pi))
# print(max(x, y, z))
# print(min(x, y, z))
# print(pow(pi, 2))
# print(math.ceil(pi))
# print(math.floor(pi))
# print(math.sqrt(pi))
# memorizing if statements (selection)
# marks = int(input("enter your marks in proper numbers (NO DECIMALS ALLOWED): \n"))
# if marks == 100:
# print("congrats! you have scored full marks!")
# elif marks >= 75:
# print("you've got an A pass")
# elif 75 > marks >= 65:
# print("you've got a B pass")
# elif 65 > marks >= 45:
# print("you've got a C pass")
# elif 45 > marks >= 33:
# print("you've got an S pass")
# elif 33 > marks >= 0:
# print("you've got a W")
# else:
# print("sorry! enter a valid mark next time!")
# a brief idea about logical operators (and/or)
# temp = int(input("enter your room temperature: \n"))
# if temp >= 0 and temp <= 35:
# print("temperature is great! go outside!")
# elif temp < 0 or temp > 35:
# print("inhabitable temperature! stay inside!")
# a brief idea about logical operators (not)
# temp = int(input("enter your room temperature: \n"))
# if not(temp >= 0 and temp <= 35):
# print("inhabitable temperature! stay inside!")
# elif not(temp < 0 or temp > 35):
# print("temperature is great! go outside!")
# a brief idea about logical operators (not)
# ferrari_worth = int(input("enter a ferrari's price: \n"))
# bank_account = int(input("how much you have got in your bitcoin wallet: \n"))
# loan = int(input("how much you willing to be in debt: \n"))
# if ferrari_worth < bank_account or ferrari_worth < loan:
# print("You can buy a rari! : )")
# if not(ferrari_worth < bank_account or ferrari_worth < loan):
# print("Sorry come another day to buy a ferrari!")
# using a while loop for a condition
# name = ""
# while len(name) == 0:
# name = input("enter your name monsieur: \n")
# print("Bonjour " + name)
# using a while loop to sum the nums in a list
# total = 0
# count = 0
# my_list = [13, 6, 611, 999, 13]
# while count < len(my_list): # instead of len(my_list); 5 can be used as well
# total = total + my_list[count]
# count = count + 1
# print("The sum of my_list is " + str(total))
# using a while to output the number of guesses
# color = "red"
# guess = " "
# guesses = 0
# while guess != color:
# guess = input("What is the color? \n")
# guesses += 1
# if guesses == 1:
# print("You took 1 try and you've guessed it right!")
# else:
# print("You took this many guesses to guess: " + str(guesses))
# for loops
# for i in range(13):
# print(i+1)
# for i in range(13, 67):
# print(i)
# for i in range(13, 66, 3): # with a third argument as a 'STEP'
# print(i)
# for i in ("supun seth xiii"):
# print(i)
#countdown
# import time
# for seconds in range(10, 0, -1):
# print(seconds)
# time.sleep(1) # halts printing each output from the for loop for a second (1 second)
# print("hello world!")
# nested for loops to print a rectangular shape from any keyboard character
# rows = int(input("enter the number of rows: \n")) # gonna be handled by the outer loop
# columns = int(input("enter the number of columns: \n")) # gonna be handled by the inner loop
# figure = input("enter any character you like: \n")
# print()
# for i in range(rows):
# for j in range(columns):
# print(figure, end="") # "end" argument will prevent the cursor from going to the next line. if it goes to the next line we won't get a rectangular shape instead it'll be like vertical line of characters.
# print()
# loop control statements: continue
# phone_number = "666-131-1776"
# for i in phone_number:
# if i == "-":
# continue
# print(i, end="")
# loop control statements: break
# while True: # similar code is in line 128
# name = input("enter your name: \n")
# if name != "":
# print("hi " + name + "!")
# break
# loop control statements: pass
# for i in range(0, 26):
# if i == 13:
# pass # passing 13 coz it's considered to be an unlucky number by some IDIOTS!
# else:
# print(i)
# lists
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites[1] = "Boruto"
# print(favorites[0])
#
# print(favorites)
#
# for i in favorites:
# print(i)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.append("How I Met Your Mother") # insert an item to the last index of a list
# print(favorites)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.remove("Beyblades") # removes the character which is similar to the argument passed to the "remove" method
# print(favorites)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.pop(0) # can delete the certain item in a list by passing the specific index as a argument to the "pop" method
# print(favorites)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.insert(3, "Teen Titans GO!") # can insert an item to the list by first passing the index we want to be added and at second the item itself as the parameter
# print(favorites)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.sort() # sorts to the alphabetical order
# print(favorites)
# numbers = [1301166, 1966, 66, 1776, 1999]
# numbers.sort() # by default sorts values in ascending order
# print(numbers)
# numbers = [1301166, 1966, 66, 1776, 1999]
# numbers.sort(reverse=True) # reverse parameter's value to True will make the sort in descending order
# print(numbers)
# favorites = ["Beyblades", "Naruto", "Stranger Things", "Dragon Ball Z", "The Office", "Modern Family"]
# favorites.clear() # every item will be deleted creating an empty list
# print(favorites)
# list append and extend
# marks = [72,65,45,83,87]
# marks1 = [56,65,89]
# count = 0
# while count < 5:
# print(marks[count])
# count +=1
# marks.append(78)
# print(marks)
# marks.extend([90,89])
# print(marks)
# print(set(marks))
# 2D Lists
# sports = ["cricket", "football", "rugby", "basketball"]
# food = ["pizza", "spaghetti", "sandwiches", "burgers", "fries"]
# animes = ["Naruto", "Dragon Ball Z", "Deltora Quest", "Death Note", "Attack on Titan"]
# twod_list = [sports, food, animes] # a 2D List
# print(twod_list)
# print(twod_list[2])
# print(twod_list[2][0])
# tuples
# student = ("supun", 22, "male")
# print(student.count("supun")) # counts how many times a certain value appears in the tuple
# print(student.index(22)) # outputs the certain index
# print()
# for i in student: # can use a for loop to print the values in a tuple
# print(i)
# print()
# if "supun" in student: # can use if statement to check the availability of a certain item
# print("supun is here in the tuple!")
# sets
# utensils = {"fork", "spoon", "knife", "spoon", "spoon", "spoon"} # does not print any duplicates since its un-indexed order changes
# dishes = {"plate", "bowl", "cup", "cup", "fork"}
# utensils.add("napkin")
# utensils.remove("fork")
# utensils.clear()
# utensils.update(dishes)
# for i in utensils:
# print(i)
# dinner_table = utensils.union(dishes) # typical \/ of sets
# for i in dinner_table:
# print(i)
# print(utensils.difference(dishes))
# print(utensils.intersection(dishes)) # typical /\ of sets
# dictionaries
# capitals = {"The USA": "Washington DC",
# "Japan": "Tokyo",
# "Australia": "Sydney",
# "The UK": "London",
# "France": "Paris"}
# print(capitals["The USA"])
# print(capitals.get("The USA")) # this is much safer since if the key is not available it'll output "None"
# print(capitals.keys()) # outputs only the keys
# print(capitals.values()) # outputs only the values
# print(capitals.items()) # outputs all the items
# for country, capital_city in capitals.items():
# print(country, ": ", capital_city)
# capitals.update({"Germany": "Berlin"})
# capitals.pop("The USA")
# capitals.clear()
# for country, capital_city in capitals.items():
# print(country, ": ", capital_city)