-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangela_yu_100_days_of_code (1).py
More file actions
559 lines (410 loc) Β· 14.5 KB
/
angela_yu_100_days_of_code (1).py
File metadata and controls
559 lines (410 loc) Β· 14.5 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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# -*- coding: utf-8 -*-
"""Angela Yu 100 days of code.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ieG0XC1xGod5R1D8vQnzKWBJbdPVa2S5
"""
#100 days of python challenge
#pizza order calculator
# π¨ Don't change the code below π
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ")
add_pepperoni = input("Do you want pepperoni? Y or N ")
extra_cheese = input("Do you want extra cheese? Y or N ")
# π¨ Don't change the code above π
#Write your code below this line π
total=0
if size =="S":
total += 15
elif size == 'M':
total += 20
else:
total += 25
if add_pepperoni == "Y":
if size =="S":
total += 2
else:
total += 3
if extra_cheese =="Y":
total += 1
print('Your final bill is: $'+str(total))
#love calculator
#For this exercise, we use the input function, if statement and concatenate
# π¨ Don't change the code below π
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
# π¨ Don't change the code above π
#Write your code below this line π
combined= name1 + name2
total=combined.lower()
t = total.count ("t")
r = total.count ("r")
u = total.count ("u")
e = total.count ("e")
true=t + r + u + e
l = total.count ("l")
o = total.count ("o")
v = total.count ("v")
e = total.count ("e")
love=l + o + v + e
true_love=str(true)+str(love)
total_score=int(true_love)
if (total_score < 10) or (total_score > 90):
print (f"Your score is {true_love}, you go together like coke and mentos.")
elif (total_score > 39) and (total_score < 51):
print (f"Your score is {true_love}, you are alright together.")
else:
print(f"Your score is {true_love}.")
#coin toss
#Remember to use the random module
#Hint: Remember to import the random module here at the top of the file. π²
# π¨ Don't change the code below π
test_seed = int(input("Create a seed number: "))
# π¨ Don't change the code above π It's only for testing your code.
#Write the rest of your code below this line π
import random
random_toss = random.randint(0, 1)
if random_toss == 1:
print ('Heads')
else:
print ('Tails')
#treasure island game
print ('Welcome to Treasure island!')
print ('Your mission is to find the treasure.')
question_1 = input("There is two door, A blue door and a red door, which way do you want to go?").lower
if question_1= 'red door'
print ('You got lucky, You may proceed in the game.')
question_2=input("There is two door, door 1 - 2 , which way do you want to go?").lower
if question_2 ='door 1'
print ('That'/s a dead end, Game over.')
else if question_2 ='door 1'
print ('Here is the treasure. Congratulations, You won.')
elif question_1 ='blue door'
print ('That'/s a dead end, Game over.')
else
print ('I didn'/t understand that, Game over.')
print ('Welcome to Treasure island!\nYour mission is to find the treasure.')
"""Retry on another way """
#treasure island game
print ('Welcome to Treasure island!')
print ('Your mission is to find the treasure.')
question_1 = input("There is two door, A blue door and a red door, which way do you want to go?").lower()
if question_1== 'red door':
print ('You got lucky. You may proceed in the game.')
question_2 = input("There is two door, door 1 - 2 , which way do you want to go?").lower
if question_2 =='door 1':
print ('That\'s a dead end, Game over.')
else:
print ('Here is the treasure. Congratulations! You won.')
else:
print ('That\'s a dead end, Game over.')
#nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[1][1])
#nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[0])
# this script print the list found in fruits list
#nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[1])
#this script print the list found in vegetable list
#nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[1][2])
#for this part, list 1 will be vegetable and list 2 will be tomatoes(counting started at 0 same with the first number)
#nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[1][3])
#for this part, list 1 will be vegetable and list 3 will be celery(counting started at 0 same with the first number)
user_choice=int(input("What do you choose? Type 0 for Scissors, 1 for Paper or 2 for Rock.\n"))
scissors =("""
_______
---' ____)____
______)
__________)
(____)
---.__(___)
""")
paper=("""
_______
---' ____)____
______)
_______)
_______)
---.__________)
""")
rock = ('''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
''')
hand=[scissors,paper,rock]
import random
random_hand=[scissors,paper,rock]
computer_choice=int((random.randint(0, 2)))
#lets define the computer choice
if computer_choice == 0 :
print('Computer chose:]}.')
print(hand[0])
elif computer_choice ==1:
print('Computer chose:')
print(hand[1])
else:
print('Computer chose:')
print(hand[2])
if user_choice >= 3 or user_choice < 0:
print ("I didn't understand that, You lose!")
else:
print("You chose: ")
print(hand[user_choice])
##print ("computer_choice is" + " "+ str(computer_choice))
##print ("user_choice is" + " "+ str(user_choice))
#lets declare the winner
if user_choice == computer_choice:
print ("Its a tie.")
elif user_choice==0 and computer_choice==2:
print ("You lose!")
elif user_choice==2 and computer_choice==0:
print ("You win!")
elif user_choice >= 3:
print ("I didn't understand that, You lose!")
elif user_choice > computer_choice:
print ("You won!")
elif user_choice < computer_choice:
print ("You lose!")
else:
print ("You lose")
hand=['Scissors','Paper','Rock']
import random
number=int(input('Pick a number(0-2)'))
computer_choice=int((random.randint(0, 2)))
print (f'Computer chose {computer_choice}.')
print (f'You chose {number}')
import random
scissors =("""
_______
---' ____)____
______)
__________)
(____)
---.__(___)
""")
paper=("""
_______
---' ____)____
______)
_______)
_______)
---.__________)
""")
rock = ('''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
''')
hand=[scissors,paper,rock]
user_choice=int(random.randint(0,2))
print(hand[user_choice])
fruits= ["Apple","Pie","Mango","Pineapple"]
for fruit in fruits:
print(fruit)
print(fruit+ ' '+ 'pie')
"""Practice for statement-this is the example in the course"""
Vegetables= ["Carrot","Potato","Monggo","Sayote"]
for fruit in Vegetables:
print(fruit)
print(fruit+ ' '+ 'silog')
"""For loop exercise-corey """
x=1
while x< 100:
break
print (x)
x += 1
# π¨ Don't change the code below π
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
# print(student_heights)
# π¨ Don't change the code above π
#Write your code below this row π
total_height = 0
for height in student_heights:
total_height += height
print(f"total height = {total_height}")
number_of_students = 0
for student in student_heights:
number_of_students += 1
print(f"number of students = {number_of_students}")
average_height = round(total_height / number_of_students)
print(average_height)
#Write your code above this line π
# π¨ Do NOT modify the code below this line π
with open('testing_copy.py', 'w') as file:
file.write('def test_func():\n')
with open('main.py', 'r') as original:
f2 = original.readlines()[0:40]
for x in f2:
file.write(" " + x)
import testing_copy
import unittest
from unittest.mock import patch
from io import StringIO
import os
class MyTest(unittest.TestCase):
def run_test(self, given_answer, expected_print):
with patch('builtins.input', return_value=given_answer), patch('sys.stdout', new=StringIO()) as fake_out:
testing_copy.test_func()
self.assertEqual(fake_out.getvalue(), expected_print)
def test_1(self):
self.run_test(given_answer='180 124 165 173 189 169 146', expected_print='total height = 1146\nnumber of students = 7\n164\n')
def test_2(self):
self.run_test(given_answer='150 142 185 120 171 184 149 199', expected_print='total height = 1300\nnumber of students = 8\n162\n')
print("\n\n\n.\n.\n.")
print('Checking that the code prints the average height (and other print statements above) rounded to the nearest integer for several different lists of heights.\n')
print('\nRunning some tests on your code:')
print(".\n.\n.")
unittest.main(verbosity=1, exit=False)
os.remove("testing_copy.py")
# π¨ Don't change the code below π
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
print(student_heights)
# π¨ Don't change the code above π
#Write your code below this row π
#use for loop in computing total height
total_height=0
for height in student_heights:
total_height += height
print (total_height)
# use for loop in computing number of students
number_of_students = 0
for student in student_heights:
number_of_students += 1
print (number_of_students)
average=round(total_height/number_of_students)
print (average)
# π¨ Don't change the code below π
student_scores = input("Input a list of student scores ").split()
for n in range(0, len(student_scores)):
student_scores[n] = int(student_scores[n])
print(student_scores)
# π¨ Don't change the code above π
#Write your code below this row π
x= 0
for n in student_scores:
if n > x:
x = n
print (x)
#for loop
total = 0
for number in range(1,101):
total += number
print (total)
total = 0
for number in range(2,101,2):
total += number
print (total)
total = 0
for number in range(1,101):
if number % 2 == 0:
total += number
print (total)
"""You are going to write a program that automatically prints the solution to the FizzBuzz game.
Your program should print each number from 1 to 100 in turn.
When the number is divisible by 3 then instead of printing the number it should print "Fizz".
When the number is divisible by 5, then instead of printing the number it should print "Buzz".`
And if the number is divisible by both 3 and 5 e.g. 15 then instead of the number it should print "FizzBuzz"
e.g. it might start off like this:
"""
#name the variable
for n in range (1,101):
if n % 3 == 0 and n % 5 == 0:
print ("FizzBuzz")
elif n % 3== 0:
print("Fizz")
elif n % 5== 0:
print ("Buzz")
else:
print (n)
#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n"))
nr_symbols=int(input(f"How many symbols would you like?\n") )
nr_numbers= int(input(f"How many numbers would you like?\n"))
password=""
for n in range (1,nr_letters+1):
random_char=random.choice(letters)
password += random_char
for n in range (1,nr_symbols+1):
random_char2=random.choice(symbols)
password += random_char2
for n in range (1,nr_numbers+1):
random_char3=random.choice(numbers)
password += random_char3
print(password)
#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n"))
nr_symbols=int(input(f"How many symbols would you like?\n") )
nr_numbers= int(input(f"How many numbers would you like?\n"))
password=""
for n in range (1,nr_letters+1):
password += random.choice(letters)
for n in range (1,nr_symbols+1):
password += random.choice(symbols)
for n in range (1,nr_numbers+1):
password += random.choice(numbers)
print(password)
#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n"))
nr_symbols=int(input(f"How many symbols would you like?\n") )
nr_numbers= int(input(f"How many numbers would you like?\n"))
password_list=[]
for n in range (1,nr_letters+1):
password_list += random.choice(letters)
for n in range (1,nr_symbols+1):
password_list += random.choice(symbols)
for n in range (1,nr_numbers+1):
password_list += random.choice(numbers)
#we can use append
# password_list.append(random.choice(numbers))
print(password_list)
random.shuffle(password_list)
print(password_list)
password =""
for x in password_list:
password += x
print(password)
print (f"Your Password is: {password}")