-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
460 lines (270 loc) · 7.41 KB
/
practice.py
File metadata and controls
460 lines (270 loc) · 7.41 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
import numpy as np
import random
'''
EX.1 @ practivepython.org
name=input("What is your name?")
age=input("How old are you?")
age_in_100_years=(2018-int(age))+100
print("Hello {}! You will turn 100 years old in {}".format(name,age_in_100_years))
EX.2 @ practivepython.org
num=input("Please enter a number: ")
if int(num)%2==0:
print("This number is even:"))
else:
print("This number is odd :(")
if int(num)%4==0:
print("Also, this number is a multiple of 4!")
else:
print("I checked if this was also a multiple of 4... it isn't.")
EX.3 @ practivepython.org
nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
nums_less=[]
num_pick=input("Pick a number: ")
for n in nums:
if n < int(num_pick):
nums_less.append(n)
else:
print("No number in this list was greater than {}".format(num_pick))
print(nums_less)
#one_line=[print(n) for n in nums if n<5 ]
EX.4 @ practivepython.org
l=[]
i=input("Please enter a number: ")
print('Here are all the divisors of {}.'.format(i))
for n in range(1,1000):
if n%int(i)==0:
l.append(n)
else:
pass
print(l)
#EX.5 @ practivepython.org
# Have to come back to this for random number generation.
# l=[]
for n in range(1,31):
l.append(random.randint(0,2001))
print(l)
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c=[]
d=random.sample(xrange(1,101),20)
e=random.sample(xrange(1,101),25)
print(d)
print(e)
for i in d:
if i not in e:
#print(str(i) + " is not in b")
c.append(i)
else:
pass
print(c)
#EX. 6 @ practivepython.org
user_str=input("Enter a string to check if palindrome: ")
rvrs_user_string=user_str[::-1]
if user_str==rvrs_user_string:
print("This word is a palindrome!")
else:
print("This word is NOT a palindrome!")
'''
'''
#EX. 7 @ practivepython.org
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
b=[print(n) for n in a if int(n)%2==0]
#EX. 8 @ practivepython.org
GAMES=5
P1_LIST=[]
P2_LIST=[]
print("\nThis game will be best of {} \n".format(GAMES))
while GAMES > 0:
p1=input("The choice is yours, Player 1. Enter rock, paper, or scissors: \n")
P1_LIST.append(p1)
p2=input("The choice is now yours, Player 2. Enter rock, paper, or scissors: \n")
P2_LIST.append(p2)
if p1==p2:
print('It is a draw!')
GAMES-=1
elif p1 == 'scissors' and p2 != 'rock':
print('Player 1 wins!')
GAMES-=1
elif p1 == 'rock' and p2 != 'paper':
print('Player 1 wins!')
GAMES-=1
elif p1 == 'paper' and p2 != 'scissors':
print('Player 1 wins!')
GAMES-=1
else:
print('Player 2 wins!')
GAMES-=1
if GAMES <=0:
print("GAME OVER!")
print('The plays\n')
print('Player 1 played: '+ str(P1_LIST))
print('Player 2 played: '+ str(P2_LIST))
#EX. 9 @ practivepython.org
for i in range(10):
rand_number=random.randint(1,9)
rand_guess=int(input("\nEnter a number between 1-9: \n"))
if rand_number==rand_guess:
print("\nYou guessed correctly!\n")
elif rand_guess>rand_number:
print("\nYour guess was too high!\n")
elif rand_guess<rand_number:
print("\nYour guess was too low!\n")
else:
pass
'''
#EX. 10 @ practivepython.org
# asks user for a number then determines whether it is a prime number.
#def PrimeSearch(num):
#EX. 11 @ practivepython.org
# rand_list=[random.randint(1,100) for x in range(30)]
# print(rand_list)
# rand_list_2=[rand_list[0],rand_list[-1]]
# print(rand_list_2)
# rand_list_2=rand_list_2*15
# print(rand_list_2)
# rand_list_2=random.shuffle(rand_list_2)
# print(rand_list_2)
#EX. 13 @ practivepython.org
# Working with set()
# my_list=[random.randint(1,100) for n in range(15)]
# a=[1,1,1,1,5,5,5,5,7,7,7,7]
# def NoDuplicate(list):
# list=set(list)
# return list
# print(NoDuplicate(my_list))
# print(NoDuplicate(a))
#EX. 14 @ practivepython.org
#EX. 18 @ practivepython.org
''' random gen of 4 digit num. for eery correct guess in correct location they have a cow. for every wrong they get a bull.
def square(num):
return num*num
if __name__ == "__main__":
user_num = int(input("Give me a number: "))
print(square(user_num))
'''
'''
FUNCTIONS2PRACTICEUSING:
round(value, decimal places =0)
sum()
split('delimtier')
e.g.
'''
'''
l = [random.randint(0,100) for i in range(30)]
print(l)
print(sum(l))
s = "This is a random string that could contain valuable information that you want to tokenize data. This will be split based on a space delimeter."
s2=s.split(" ")
print(s2)
# This list method is very important in AI and NLP e.g. sentiment analysis.
#
'''
# Set problems
# Sets are kind of like lists but remove duplicate values.
# s1=set([1,1,2,3,4,5,5]) # alternately: s1={1,2,3,4,5} ; to create empty set: set()
# print(s1)
# s1.add(6)
# print(s1)
# s1.update([6,7,8,9,10])
# print(s1)
# s1=s1.remove(9)
# print(s1)
# # But what can we do with sets() ?
# s1={1,2,3}
# s2={2,3,4}
# s3={3,4,5}
# s4 = s1.intersection(s2,s3)
# s5 = s1.difference(s2)
# print(s4)
# print(s5)
#EX. 20 @ practivepython.org
# rlist=[random.randint(1,100) for n in range(20)]
# rnum=int(input("Enter a number between 1-100: "))
# def func(list,num):
# list=set(list)
# if num in list:
# return True
# else:
# return False
# print(func(rlist,rnum))
# print(rlist)
#EX. 21 @ practivepython.org
# writing to a file
# be sure to close a file after creating and modifying it.
#
# with open('example.txt','w') as open_file:
# open_file.write('The first string...')
# # open_file.close() is not necessary because of the with statement
#EX. 25 @ practivepython.org
# MINIMUM = 0
# MAXIMUM = 100
# NUMBER = random.randint(MINIMUM,MAXIMUM)
# TRY = 0
# RUNNING = True
# ANSWER = None
# while RUNNING:
# print("Is it {}? ".format(str(NUMBER)))
# ANSWER = input()
# # if 'no' in ANSWER.lower() and "lower" in ANSWER.lower():
# # NUMBER -= random.randint(1,4)
# # elif 'no' in ANSWER.lower() and "higher" in ANSWER.lower():
# # NUMBER += random.randint(1,4)
# if ANSWER.lower() == 'no':
# print("Higher or lower?")
# ANSWER = input()
# if ANSWER.lower() == 'higher':
# NUMBER += random.randint(1,4)
# elif ANSWER.lower() == 'lower':
# NUMBER -= random.randint(1,4)
# if ANSWER.lower() == 'yes':
# if TRY < 2:
# print("Yes! It only took me {}".format(str(TRY)))
# elif TRY < 2 and TRY < 10:
# print("Pretty well for a robot, {} tries".format(str(TRY)))
# else:
# print("That's so bad, {} tries.".format(str(TRY)))
# RUNNING = False
# TRY += 1
# print("GG")
# binary search
# RUNNING = True
# a = [1,3,5,4,2,3,5,6,8,9,19]
# a = set(a)
# print(a)
# print(int(len(a)/2))
# my_list = [random.randint(1,100) for n in range(1000)]
# my_list = set(my_list)
# my_list = list(my_list)
# target = 58
# guess = 0
# while not (len(my_list)==1 or guess==target):
# center_index = int(len(my_list)/2)
# guess = my_list[center_index]
# if guess > target:
# my_list=my_list[:center_index]
# elif guess < target:
# my_list=my_list[center_index:]
# if guess == target:
# print("Nailed it!")
#EX. 27 @ practivepython.org
# square=" --- \n| |\n --- "
# def print_horiz_line():
# print(" --- " * board_size)
# def print_vert_line():
# print("| " * (board_size + 1))
# if __name__ == "__main__":
# board_size=int(input('What size game board? '))
# for i in range(board_size):
# print_horiz_line()
# print_vert_line()
# print_horiz_line()
#EX. 28 @ practivepython.org
def findMax(num1,num2,num3):
# l=[]
# l = []
# l.append(num1)
# l.append(num2)
# l.append(num3)
# print(max(l))
print(max(num1,num2,num3))
findMax(1,2,3)