From 17a12a983fc07a9fc96f9fa2d5f2726049cad292 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:33:35 +0900 Subject: [PATCH 01/42] Create temperature.py --- 1_beginner/chapter4/practice/temperature.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 1_beginner/chapter4/practice/temperature.py diff --git a/1_beginner/chapter4/practice/temperature.py b/1_beginner/chapter4/practice/temperature.py new file mode 100644 index 00000000..0734720b --- /dev/null +++ b/1_beginner/chapter4/practice/temperature.py @@ -0,0 +1,14 @@ +""" +Hoppity the Rabbit wrote some code, but it doesn't run correctly and he needs your help! +The following program is supposed to print a string based on a numerical input of the temperature. +See if you can fix it for him! +""" +#I added some comments to aid you. Good luck! - Hoppity +temp = int(input("Enter temperature: ")) #possible input range is 0-100 + +if(temp < 100): #60-100 is hot + print('hot') +if(temp <= 60): #30-59 is normal + print('normal') +if(temp < 30): #0-29 is cold + print('cold') From ba1fa01ab29d43f7867e90a2167b63873e8d7fb0 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:34:19 +0900 Subject: [PATCH 02/42] Create square.py --- 1_beginner/chapter4/solutions/square.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 1_beginner/chapter4/solutions/square.py diff --git a/1_beginner/chapter4/solutions/square.py b/1_beginner/chapter4/solutions/square.py new file mode 100644 index 00000000..532a6246 --- /dev/null +++ b/1_beginner/chapter4/solutions/square.py @@ -0,0 +1,5 @@ +x = int(input("Enter a number: ")) +if(x % 2 == 0): + print(x**2) +else: + print(x) From dd4fbaf24070180dcc22c791dffd8f94710d92df Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:34:50 +0900 Subject: [PATCH 03/42] Create menu.py --- 1_beginner/chapter4/solutions/menu.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 1_beginner/chapter4/solutions/menu.py diff --git a/1_beginner/chapter4/solutions/menu.py b/1_beginner/chapter4/solutions/menu.py new file mode 100644 index 00000000..ce2bfad1 --- /dev/null +++ b/1_beginner/chapter4/solutions/menu.py @@ -0,0 +1,9 @@ +food = input("Enter food order: ") +drink = input("Enter drink order: ") +price = 1000000000 +if(food == 'french toast' and drink == 'coffee'): + price = price - 1 +elif(food == 'chicken soup' or drink == 'apple juice'): + price = price + 1 + +print('The total price is $' + str(price)) From 3a384171fde7803ebaad3ec05246580f68e0668c Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:35:16 +0900 Subject: [PATCH 04/42] Create monthandday.py --- 1_beginner/chapter4/solutions/monthandday.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 1_beginner/chapter4/solutions/monthandday.py diff --git a/1_beginner/chapter4/solutions/monthandday.py b/1_beginner/chapter4/solutions/monthandday.py new file mode 100644 index 00000000..cbd70e95 --- /dev/null +++ b/1_beginner/chapter4/solutions/monthandday.py @@ -0,0 +1,8 @@ +month = input('Enter the month: ') +day = input('Enter the day: ') + +if(month == 10 and day == 31): + print('Boo!') +elif(month == 4 and day == 1): + print('April fools!') + From 7277ebf4df6b5355283603bedecd944392f910a9 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:35:41 +0900 Subject: [PATCH 05/42] Create walk.py --- 1_beginner/chapter4/solutions/walk.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 1_beginner/chapter4/solutions/walk.py diff --git a/1_beginner/chapter4/solutions/walk.py b/1_beginner/chapter4/solutions/walk.py new file mode 100644 index 00000000..cf8146f7 --- /dev/null +++ b/1_beginner/chapter4/solutions/walk.py @@ -0,0 +1,20 @@ +first_hour = int(input('Enter the hour of the time of the first walk: ')) +first_minute = int(input('Enter the minute of the time of the first walk: ')) + +second_hour = first_hour + 1 + 6 #add first_hour + 1 is when the first walk ends, 6 hours later the second walk should start +second_minute = first_minute + +current_hour = int(input('Enter the current hour: ')) +current_minute = int(input('Enter the current minute: ')) + +if(current_hour > second_hour): + print('Late') +elif(current_hour < second_hour): + print('Early') +else: #current_hour == second_hour + if(current_minute > second_minute): + print('Late') + elif(current_minute < second_minute): + print('Early') + else: #current_minute == second_minute + print('Now') From e480f5603c85888324410ca1ea3ab22a7afee789 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Fri, 26 Jun 2020 11:36:11 +0900 Subject: [PATCH 06/42] Create temperature.py --- 1_beginner/chapter4/solutions/temperature.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 1_beginner/chapter4/solutions/temperature.py diff --git a/1_beginner/chapter4/solutions/temperature.py b/1_beginner/chapter4/solutions/temperature.py new file mode 100644 index 00000000..b6333ec4 --- /dev/null +++ b/1_beginner/chapter4/solutions/temperature.py @@ -0,0 +1,10 @@ +temp = int(input("Enter temperature: ")) #possible input range is 0-100 + +if(60 <= temp <= 100): #60-100 is hot + print('hot') +if(30 <= temp < 60): #30-59 is normal + print('normal') +if(0 <= temp < 30): #0-29 is cold + print('cold') + +#alternatively, you can also use elif From 0b80df4ca1223b7159cc27916dfb27be05b3b255 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:54:01 +0900 Subject: [PATCH 07/42] Create too_long --- 1_beginner/chapter6/examples/too_long | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 1_beginner/chapter6/examples/too_long diff --git a/1_beginner/chapter6/examples/too_long b/1_beginner/chapter6/examples/too_long new file mode 100644 index 00000000..9a34a81e --- /dev/null +++ b/1_beginner/chapter6/examples/too_long @@ -0,0 +1,5 @@ +""" +Print and remove all elements in a given list with length greater than 4. +""" +#example list to help you test your code +the_list = ['dragon', 'cab', 'science', 'dove', 'lime', 'river', 'pop'] From 8352924fd6f5fa741ba5737091780b65fa4a2633 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:56:53 +0900 Subject: [PATCH 08/42] Create too_long_sol solution to too_long --- 1_beginner/chapter6/too_long_sol | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 1_beginner/chapter6/too_long_sol diff --git a/1_beginner/chapter6/too_long_sol b/1_beginner/chapter6/too_long_sol new file mode 100644 index 00000000..8548b7d8 --- /dev/null +++ b/1_beginner/chapter6/too_long_sol @@ -0,0 +1,9 @@ +""" +Print and remove all elements in a given list with length greater than 4. +""" +the_list = ['dragon', 'cab', 'science', 'dove', 'lime', 'river', 'pop'] + +for x in the_list: #iterates through every element in the_list + if(len(x) > 4): #if length is greater than 4 + print(x) #print it + the_list.remove(x) From 949c66a18f6afec2912e6fc4ffa37628d55ae847 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:58:54 +0900 Subject: [PATCH 09/42] Create virtual_pet --- 1_beginner/chapter6/virtual_pet | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 1_beginner/chapter6/virtual_pet diff --git a/1_beginner/chapter6/virtual_pet b/1_beginner/chapter6/virtual_pet new file mode 100644 index 00000000..4c6dea22 --- /dev/null +++ b/1_beginner/chapter6/virtual_pet @@ -0,0 +1,13 @@ +""" +Code a virtual pet! +First, create three variables: name, hunger, and happiness. +Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') +Make a program that satisfies the following: + Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. + Print "[pet name] wants more attention" when happiness is below 5. + Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. + Takes input from the user. + If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. + If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. + If the user enters 'quit', end the program. +""" From 6048c9ff18f29b65862a86459e922e3d1de831f6 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:00:10 +0900 Subject: [PATCH 10/42] Create virtual_pet_sol --- 1_beginner/chapter6/virtual_pet_sol | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 1_beginner/chapter6/virtual_pet_sol diff --git a/1_beginner/chapter6/virtual_pet_sol b/1_beginner/chapter6/virtual_pet_sol new file mode 100644 index 00000000..c4f0c40d --- /dev/null +++ b/1_beginner/chapter6/virtual_pet_sol @@ -0,0 +1,35 @@ +""" +Code a virtual pet! +First, create three variables: name, hunger, and happiness. +Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') +Make a program that satisfies the following: + Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. + Print "[pet name] wants more attention" when happiness is below 5. + Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. + Takes input from the user. + If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. + If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. + If the user enters 'quit', end the program. +""" + +name = 'Otto' +hunger = 6 +happiness = 0 + +cmd = input('> ') +while(cmd != 'quit'): #Exits loop when user quits + if(cmd == 'feed'): + hunger -= 2 #Otto is fed, hunger decreases + happiness -= 1 #Otto is not pet, happiness decreases + elif(cmd == 'pet'): + happiness += 2 #Otto is pet, happiness increases + hunger += 1 #Otto is not fed, hunger increases + if(hunger > 5): #Otto is not fed enough + print(name + ' is hungry') + if(happiness < 5): #Otto is not pet enough + print(name + ' wants more attention') + elif(hunger <= 5 and happiness >= 5): #Otto is satisfied! + print(name + ' feels happy') + cmd = input('> ') #Keep taking user input until user quits + +# Feel free to customize your virtual pet by changing the how much the hunger and happiness variables increase and decrease, or add more actions! From ba10022c5f4da94c763eff0f8bd654260451506a Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:01:27 +0900 Subject: [PATCH 11/42] Create too_long --- 1_beginner/chapter6/too_long | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 1_beginner/chapter6/too_long diff --git a/1_beginner/chapter6/too_long b/1_beginner/chapter6/too_long new file mode 100644 index 00000000..d26852b3 --- /dev/null +++ b/1_beginner/chapter6/too_long @@ -0,0 +1,5 @@ +""" +Print and remove all elements in a given list with length greater than 4. +""" +#list to help you test your code +the_list = ['dragon', 'cab', 'science', 'dove', 'lime', 'river', 'pop'] From 186451bbe2e9ee6a60408071c4abfd1d6435600f Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:02:21 +0900 Subject: [PATCH 12/42] Create integer_info --- 1_beginner/chapter6/integer_info | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 1_beginner/chapter6/integer_info diff --git a/1_beginner/chapter6/integer_info b/1_beginner/chapter6/integer_info new file mode 100644 index 00000000..150fcecb --- /dev/null +++ b/1_beginner/chapter6/integer_info @@ -0,0 +1,11 @@ +""" +Create a program that takes an integer as input and creates a list with the following elements: + The number of digits + The last digit + A 'True' boolean value if the number is even, 'False' if odd +Print the list. +Some examples are given to help check your work. +""" + +#Example 1: The input 123456 should print [6, 6, True] +#Example 2: The input 101202303 should print [9, 3, False] From be7f4a9fe9d10ebd4bbd5e97ac21b5e5bb57a2e6 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:02:52 +0900 Subject: [PATCH 13/42] Create integer_info_sol --- 1_beginner/chapter6/integer_info_sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 1_beginner/chapter6/integer_info_sol diff --git a/1_beginner/chapter6/integer_info_sol b/1_beginner/chapter6/integer_info_sol new file mode 100644 index 00000000..42573b2a --- /dev/null +++ b/1_beginner/chapter6/integer_info_sol @@ -0,0 +1,13 @@ +""" +Create a program that takes an integer as input and creates a list with the following elements: + The number of digits + The last digit + A 'True' boolean value if the number is even, 'False' if odd +Print the list. +Some examples are given to help check your work. +""" +#Example 1: The input 123456 should print [6, 6, True] +#Example 2: The input 101202303 should print [9, 3, False] + +num = int(input()) #convert string input to int +print([len(str(num)), num % 10, (num % 2 == 0)]) #taking the modulo of 10 of any number will return its last digit From e2c0bf323d069abd8d039f3e9104da799fb79966 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:04:06 +0900 Subject: [PATCH 14/42] Create snookle_game --- 1_beginner/chapter6/snookle_game | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 1_beginner/chapter6/snookle_game diff --git a/1_beginner/chapter6/snookle_game b/1_beginner/chapter6/snookle_game new file mode 100644 index 00000000..7dc5d995 --- /dev/null +++ b/1_beginner/chapter6/snookle_game @@ -0,0 +1,16 @@ +""" +Snookle the sheep wants to play a game. +Given a list of positive integers and a main number, the player iterates +through each element in the list and chooses to either add it or +to subtract it from the current main number. +This is done by having the user enter either 'add' or 'subtract' every turn. +The main number will be updated to the new value. +A player wins if they make 12 to be the main number. +If the end of the list is reached, go back to the first element +in the list and keep going until the player wins. +Code the game for Snookle! +""" + +#example values to get you started +nums = [3,1,4,2,6,5,8,10] +main = 7 From ccf512ca04707be69d2e2a43ae17d5f07570ee27 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:04:54 +0900 Subject: [PATCH 15/42] Create snookle_game_sol --- 1_beginner/chapter6/snookle_game_sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1_beginner/chapter6/snookle_game_sol diff --git a/1_beginner/chapter6/snookle_game_sol b/1_beginner/chapter6/snookle_game_sol new file mode 100644 index 00000000..0e92db4b --- /dev/null +++ b/1_beginner/chapter6/snookle_game_sol @@ -0,0 +1,19 @@ +nums = [3,1,4,2,6,5,8,10] +main = 7 + +choice = '' +win = False #The game keeps going until this variable is set to True + +while (not win): + for i in nums: + print('main number is currently ' + str(main)) #this is optional, but it's easier for the players since they won't have to keep track of the math + choice = input("[add] or [subtract] " + str(i) + "?\n> ") #text is also optional, I just added it to make it more user-friendly + if(choice == 'add'): #The user chooses to add + main += i #update main value + elif(choice == 'subtract'): #The user chooses to subtract + main -= i #update main value + if(main == 12): #If the main number if 12, the user has won! + win = True #This will make the program exit out of the while loop, thus ending the game + break #This takes us out of the for loop and straight to the while statement + +print('Congrats you won the game!') From ac88ba3feba364ffaf5a323c4909d540db97f9c1 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:05:53 +0900 Subject: [PATCH 16/42] Create monty_hall --- 1_beginner/chapter6/monty_hall | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 1_beginner/chapter6/monty_hall diff --git a/1_beginner/chapter6/monty_hall b/1_beginner/chapter6/monty_hall new file mode 100644 index 00000000..6a759039 --- /dev/null +++ b/1_beginner/chapter6/monty_hall @@ -0,0 +1,27 @@ +""" +Code the classic Monty Hall problem! +The following is a description of the Monty Hall Problem: + There are three closed doors, 2 have goats behind them, only one has a car behind it. + You don't know which door has what. The goal is to pick the door that has the car behind it. + After you make a choice, Monty (the host) opens a door that you did not choose, revealing a goat. + You are then asked whether you want to change your choice to the other door. + The door you chose is more likely to have a car if you switch to the other door, apparantly! +More step-by-step instructions are commented below. +Read more about the Monty Hall Problem here: (https://betterexplained.com/articles/understanding-the-monty-hall-problem/) +""" +#Make the Monty Hall game repeat 6 times. + +#Make a list that represents the three closed doors, 'G' for the doors that have a goat, 'C' for the door that has a car. +#This step has already been done for you. +import random +monty_hall = ['G', 'G', 'C'] + +random.shuffle(monty_hall) #The shuffle function from the random module randomizes the doors every loop + +#The user enters their 1st choice. + +#A door that has a goat is revealed, cannot be the one user chose + +#The user is prompted to choose again + +#The prize behind the user's ultimate choice is revealed! From e87307693015389fc48d818a531f735ec06e5cb4 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:06:29 +0900 Subject: [PATCH 17/42] Create monty_hall_sol --- 1_beginner/chapter6/monty_hall_sol | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 1_beginner/chapter6/monty_hall_sol diff --git a/1_beginner/chapter6/monty_hall_sol b/1_beginner/chapter6/monty_hall_sol new file mode 100644 index 00000000..2f8aad35 --- /dev/null +++ b/1_beginner/chapter6/monty_hall_sol @@ -0,0 +1,34 @@ +""" +Code the classic Monty Hall problem! +The following is a description of the Monty Hall Problem: + There are three closed doors, 2 have goats behind them, only one has a car behind it. + You don't know which door has what. The goal is to pick the door that has the car behind it. + After you make a choice, Monty (the host) opens a door that you did not choose, revealing a goat. + You are then asked whether you want to change your choice to the other door. + The door you chose is more likely to have a car if you switch to the other door, apparantly! +More step-by-step instructions are commented below. +Read more about the Monty Hall Problem here: (https://betterexplained.com/articles/understanding-the-monty-hall-problem/) +""" +#Make a list that represents the three closed doors, 'G' for the doors that have a goat, 'C' for the door that has a car. +import random +monty_hall = ['G', 'G', 'C'] + +#Make the Monty Hall game repeat 6 times. +for i in range(6): + random.shuffle(monty_hall) + #The user enters their 1st choice + choice = input("Choose from doors 1, 2, and 3... : ") + #A door that has a goat is revealed, cannot be the one user chose + reveal = list(monty_hall) #makes a duplicate list to avoid messing up the original + reveal[int(choice) - 1] = '-' #removes user's choice so that it won't be opened, but keeps in the element to not mess up the indices + print("Monty opens door " + str(reveal.index('G') + 1) + " to reveal a goat!") + #The user is prompted to choose again + choice = input("Re-enter your choice. You have the option to switch to the other door.\n> ") + print("You got... ") + #The prize behind the user's ultimate choice is revealed! + if(monty_hall[int(choice) - 1] == 'C'): + print("a car! Congratulations!") + else: + print("a goat! Better luck next time!") + + input("Type anything to play again\n> ") From e743e275da789b3a129e2fde3a09d403e341310c Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:09:15 +0900 Subject: [PATCH 18/42] Create virtual_pet --- 1_beginner/chapter5/practice/virtual_pet | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 1_beginner/chapter5/practice/virtual_pet diff --git a/1_beginner/chapter5/practice/virtual_pet b/1_beginner/chapter5/practice/virtual_pet new file mode 100644 index 00000000..4c6dea22 --- /dev/null +++ b/1_beginner/chapter5/practice/virtual_pet @@ -0,0 +1,13 @@ +""" +Code a virtual pet! +First, create three variables: name, hunger, and happiness. +Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') +Make a program that satisfies the following: + Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. + Print "[pet name] wants more attention" when happiness is below 5. + Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. + Takes input from the user. + If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. + If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. + If the user enters 'quit', end the program. +""" From e80ec5903d9645e5641aa75a38146c0b88146ed8 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:10:25 +0900 Subject: [PATCH 19/42] Create virtual_pet --- 1_beginner/chapter5/solutions/virtual_pet | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 1_beginner/chapter5/solutions/virtual_pet diff --git a/1_beginner/chapter5/solutions/virtual_pet b/1_beginner/chapter5/solutions/virtual_pet new file mode 100644 index 00000000..c4f0c40d --- /dev/null +++ b/1_beginner/chapter5/solutions/virtual_pet @@ -0,0 +1,35 @@ +""" +Code a virtual pet! +First, create three variables: name, hunger, and happiness. +Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') +Make a program that satisfies the following: + Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. + Print "[pet name] wants more attention" when happiness is below 5. + Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. + Takes input from the user. + If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. + If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. + If the user enters 'quit', end the program. +""" + +name = 'Otto' +hunger = 6 +happiness = 0 + +cmd = input('> ') +while(cmd != 'quit'): #Exits loop when user quits + if(cmd == 'feed'): + hunger -= 2 #Otto is fed, hunger decreases + happiness -= 1 #Otto is not pet, happiness decreases + elif(cmd == 'pet'): + happiness += 2 #Otto is pet, happiness increases + hunger += 1 #Otto is not fed, hunger increases + if(hunger > 5): #Otto is not fed enough + print(name + ' is hungry') + if(happiness < 5): #Otto is not pet enough + print(name + ' wants more attention') + elif(hunger <= 5 and happiness >= 5): #Otto is satisfied! + print(name + ' feels happy') + cmd = input('> ') #Keep taking user input until user quits + +# Feel free to customize your virtual pet by changing the how much the hunger and happiness variables increase and decrease, or add more actions! From 9974024c35a4a413421174cc8f6d27ecf810fd2f Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:10:44 +0900 Subject: [PATCH 20/42] Rename virtual_pet to virtual_pet.py --- 1_beginner/chapter5/solutions/{virtual_pet => virtual_pet.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter5/solutions/{virtual_pet => virtual_pet.py} (100%) diff --git a/1_beginner/chapter5/solutions/virtual_pet b/1_beginner/chapter5/solutions/virtual_pet.py similarity index 100% rename from 1_beginner/chapter5/solutions/virtual_pet rename to 1_beginner/chapter5/solutions/virtual_pet.py From 46e2d6198735ce8daf71935ac6576ba08db0e341 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:11:06 +0900 Subject: [PATCH 21/42] Rename virtual_pet to virtual_pet.py --- 1_beginner/chapter5/practice/{virtual_pet => virtual_pet.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter5/practice/{virtual_pet => virtual_pet.py} (100%) diff --git a/1_beginner/chapter5/practice/virtual_pet b/1_beginner/chapter5/practice/virtual_pet.py similarity index 100% rename from 1_beginner/chapter5/practice/virtual_pet rename to 1_beginner/chapter5/practice/virtual_pet.py From 6401be9ac893455c429cc224c594fc15ebbbf8ec Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:11:25 +0900 Subject: [PATCH 22/42] Rename integer_info to integer_info.py --- 1_beginner/chapter6/{integer_info => integer_info.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{integer_info => integer_info.py} (100%) diff --git a/1_beginner/chapter6/integer_info b/1_beginner/chapter6/integer_info.py similarity index 100% rename from 1_beginner/chapter6/integer_info rename to 1_beginner/chapter6/integer_info.py From 0ded7f6dd4ff5bbeb1e997b5da9624ef3d7c0d49 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:11:41 +0900 Subject: [PATCH 23/42] Rename integer_info_sol to integer_info_sol.py --- 1_beginner/chapter6/{integer_info_sol => integer_info_sol.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{integer_info_sol => integer_info_sol.py} (100%) diff --git a/1_beginner/chapter6/integer_info_sol b/1_beginner/chapter6/integer_info_sol.py similarity index 100% rename from 1_beginner/chapter6/integer_info_sol rename to 1_beginner/chapter6/integer_info_sol.py From a95a5412c56e53aeff6b889669ced7c847802bd6 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:11:57 +0900 Subject: [PATCH 24/42] Rename monty_hall to monty_hall.py --- 1_beginner/chapter6/{monty_hall => monty_hall.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{monty_hall => monty_hall.py} (100%) diff --git a/1_beginner/chapter6/monty_hall b/1_beginner/chapter6/monty_hall.py similarity index 100% rename from 1_beginner/chapter6/monty_hall rename to 1_beginner/chapter6/monty_hall.py From 2755a33de4d002cbdfb1541227fdbfb3dd5bcb4e Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:12:13 +0900 Subject: [PATCH 25/42] Rename monty_hall_sol to monty_hall_sol.py --- 1_beginner/chapter6/{monty_hall_sol => monty_hall_sol.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{monty_hall_sol => monty_hall_sol.py} (100%) diff --git a/1_beginner/chapter6/monty_hall_sol b/1_beginner/chapter6/monty_hall_sol.py similarity index 100% rename from 1_beginner/chapter6/monty_hall_sol rename to 1_beginner/chapter6/monty_hall_sol.py From 4c62bf662f7fe83a0b98976b625fb012310a8fae Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:12:27 +0900 Subject: [PATCH 26/42] Rename snookle_game to snookle_game.py --- 1_beginner/chapter6/{snookle_game => snookle_game.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{snookle_game => snookle_game.py} (100%) diff --git a/1_beginner/chapter6/snookle_game b/1_beginner/chapter6/snookle_game.py similarity index 100% rename from 1_beginner/chapter6/snookle_game rename to 1_beginner/chapter6/snookle_game.py From ffbcfd0d2ce40f0939841e988b0654f3946aa82d Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:12:39 +0900 Subject: [PATCH 27/42] Rename snookle_game_sol to snookle_game_sol.py --- 1_beginner/chapter6/{snookle_game_sol => snookle_game_sol.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{snookle_game_sol => snookle_game_sol.py} (100%) diff --git a/1_beginner/chapter6/snookle_game_sol b/1_beginner/chapter6/snookle_game_sol.py similarity index 100% rename from 1_beginner/chapter6/snookle_game_sol rename to 1_beginner/chapter6/snookle_game_sol.py From 234091317df42baf5ac7d8a4ae1b5b70ed7ceb09 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:13:00 +0900 Subject: [PATCH 28/42] Rename too_long to too_long.py --- 1_beginner/chapter6/{too_long => too_long.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{too_long => too_long.py} (100%) diff --git a/1_beginner/chapter6/too_long b/1_beginner/chapter6/too_long.py similarity index 100% rename from 1_beginner/chapter6/too_long rename to 1_beginner/chapter6/too_long.py From 880e3b251967afddde6fbb009a9c5c5a90ad71bc Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:13:14 +0900 Subject: [PATCH 29/42] Rename too_long_sol to too_long_sol.py --- 1_beginner/chapter6/{too_long_sol => too_long_sol.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1_beginner/chapter6/{too_long_sol => too_long_sol.py} (100%) diff --git a/1_beginner/chapter6/too_long_sol b/1_beginner/chapter6/too_long_sol.py similarity index 100% rename from 1_beginner/chapter6/too_long_sol rename to 1_beginner/chapter6/too_long_sol.py From c477be83ee37d59a171c05f27503f6ed5ebe2308 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:24:18 +0900 Subject: [PATCH 30/42] Update integer_info.py --- 1_beginner/chapter6/integer_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/integer_info.py b/1_beginner/chapter6/integer_info.py index 150fcecb..69e17e10 100644 --- a/1_beginner/chapter6/integer_info.py +++ b/1_beginner/chapter6/integer_info.py @@ -1,4 +1,5 @@ """ +Integer Info Create a program that takes an integer as input and creates a list with the following elements: The number of digits The last digit From 00875579bf83374a8d84143327b753c41c34e83e Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:24:36 +0900 Subject: [PATCH 31/42] Update integer_info_sol.py --- 1_beginner/chapter6/integer_info_sol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/integer_info_sol.py b/1_beginner/chapter6/integer_info_sol.py index 42573b2a..fe6c67f6 100644 --- a/1_beginner/chapter6/integer_info_sol.py +++ b/1_beginner/chapter6/integer_info_sol.py @@ -1,4 +1,5 @@ """ +Integer Info Create a program that takes an integer as input and creates a list with the following elements: The number of digits The last digit From 5eef74c9c4fa58d2956625bd90f12c72d0ac6b2c Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:25:36 +0900 Subject: [PATCH 32/42] Update monty_hall.py --- 1_beginner/chapter6/monty_hall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/monty_hall.py b/1_beginner/chapter6/monty_hall.py index 6a759039..a2b79c85 100644 --- a/1_beginner/chapter6/monty_hall.py +++ b/1_beginner/chapter6/monty_hall.py @@ -1,4 +1,5 @@ """ +Monty Hall Code the classic Monty Hall problem! The following is a description of the Monty Hall Problem: There are three closed doors, 2 have goats behind them, only one has a car behind it. From 60bc26aaec2b1f32f74ec3df7247a8df60c4e3f5 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:26:07 +0900 Subject: [PATCH 33/42] Update monty_hall_sol.py --- 1_beginner/chapter6/monty_hall_sol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/monty_hall_sol.py b/1_beginner/chapter6/monty_hall_sol.py index 2f8aad35..07ba7902 100644 --- a/1_beginner/chapter6/monty_hall_sol.py +++ b/1_beginner/chapter6/monty_hall_sol.py @@ -1,4 +1,5 @@ """ +Monty Hall Code the classic Monty Hall problem! The following is a description of the Monty Hall Problem: There are three closed doors, 2 have goats behind them, only one has a car behind it. From e6599ff2e065ff50a8179e264b922c62096573e7 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:26:25 +0900 Subject: [PATCH 34/42] Update snookle_game.py --- 1_beginner/chapter6/snookle_game.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/snookle_game.py b/1_beginner/chapter6/snookle_game.py index 7dc5d995..a0e78cad 100644 --- a/1_beginner/chapter6/snookle_game.py +++ b/1_beginner/chapter6/snookle_game.py @@ -1,4 +1,5 @@ """ +Snookle Game Snookle the sheep wants to play a game. Given a list of positive integers and a main number, the player iterates through each element in the list and chooses to either add it or From 64fbafa1987fd05091bdc6ee1c72ee7d333068d2 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:27:06 +0900 Subject: [PATCH 35/42] Update snookle_game_sol.py --- 1_beginner/chapter6/snookle_game_sol.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/1_beginner/chapter6/snookle_game_sol.py b/1_beginner/chapter6/snookle_game_sol.py index 0e92db4b..0a6f440c 100644 --- a/1_beginner/chapter6/snookle_game_sol.py +++ b/1_beginner/chapter6/snookle_game_sol.py @@ -1,3 +1,17 @@ +""" +Snookle Game +Snookle the sheep wants to play a game. +Given a list of positive integers and a main number, the player iterates +through each element in the list and chooses to either add it or +to subtract it from the current main number. +This is done by having the user enter either 'add' or 'subtract' every turn. +The main number will be updated to the new value. +A player wins if they make 12 to be the main number. +If the end of the list is reached, go back to the first element +in the list and keep going until the player wins. +Code the game for Snookle! +""" + nums = [3,1,4,2,6,5,8,10] main = 7 From c972c5e4152cc6769d76e9114cd24378fdb5f371 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:27:31 +0900 Subject: [PATCH 36/42] Update too_long.py --- 1_beginner/chapter6/too_long.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/too_long.py b/1_beginner/chapter6/too_long.py index d26852b3..d458adda 100644 --- a/1_beginner/chapter6/too_long.py +++ b/1_beginner/chapter6/too_long.py @@ -1,4 +1,5 @@ """ +Too Long Print and remove all elements in a given list with length greater than 4. """ #list to help you test your code From 03b6faaf9ec716569ed4ead39bd4c0b3df94f94a Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:27:53 +0900 Subject: [PATCH 37/42] Update too_long_sol.py --- 1_beginner/chapter6/too_long_sol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/too_long_sol.py b/1_beginner/chapter6/too_long_sol.py index 8548b7d8..b5cdb31e 100644 --- a/1_beginner/chapter6/too_long_sol.py +++ b/1_beginner/chapter6/too_long_sol.py @@ -1,4 +1,5 @@ """ +Too Long Print and remove all elements in a given list with length greater than 4. """ the_list = ['dragon', 'cab', 'science', 'dove', 'lime', 'river', 'pop'] From 9d31bccf4b99920e984dd271311c0917c68b3132 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:28:09 +0900 Subject: [PATCH 38/42] Update virtual_pet --- 1_beginner/chapter6/virtual_pet | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter6/virtual_pet b/1_beginner/chapter6/virtual_pet index 4c6dea22..04a7442f 100644 --- a/1_beginner/chapter6/virtual_pet +++ b/1_beginner/chapter6/virtual_pet @@ -1,4 +1,5 @@ """ +Virtual Pet Code a virtual pet! First, create three variables: name, hunger, and happiness. Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') From 31ddc7afc930aa8d134c1cfce9dc7c1494b403f7 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:29:27 +0900 Subject: [PATCH 39/42] Delete virtual_pet --- 1_beginner/chapter6/virtual_pet | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 1_beginner/chapter6/virtual_pet diff --git a/1_beginner/chapter6/virtual_pet b/1_beginner/chapter6/virtual_pet deleted file mode 100644 index 04a7442f..00000000 --- a/1_beginner/chapter6/virtual_pet +++ /dev/null @@ -1,14 +0,0 @@ -""" -Virtual Pet -Code a virtual pet! -First, create three variables: name, hunger, and happiness. -Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') -Make a program that satisfies the following: - Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. - Print "[pet name] wants more attention" when happiness is below 5. - Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. - Takes input from the user. - If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. - If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. - If the user enters 'quit', end the program. -""" From e5dba874f3a8cb52a077aed4367594d9e78bef27 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:29:35 +0900 Subject: [PATCH 40/42] Delete virtual_pet_sol --- 1_beginner/chapter6/virtual_pet_sol | 35 ----------------------------- 1 file changed, 35 deletions(-) delete mode 100644 1_beginner/chapter6/virtual_pet_sol diff --git a/1_beginner/chapter6/virtual_pet_sol b/1_beginner/chapter6/virtual_pet_sol deleted file mode 100644 index c4f0c40d..00000000 --- a/1_beginner/chapter6/virtual_pet_sol +++ /dev/null @@ -1,35 +0,0 @@ -""" -Code a virtual pet! -First, create three variables: name, hunger, and happiness. -Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') -Make a program that satisfies the following: - Print "[pet name] is hungry" when hunger is above 5, where [pet name] is the name variable. - Print "[pet name] wants more attention" when happiness is below 5. - Print "[pet name] feels happy" when hunger is equal to or less than 5, and happiness is equal to or greater than 5. - Takes input from the user. - If the user enters 'feed', decrease hunger by 2. Increase by 1 otherwise. - If the user enters 'pet', increase happiness by 2. Decrease by 1 otherwise. - If the user enters 'quit', end the program. -""" - -name = 'Otto' -hunger = 6 -happiness = 0 - -cmd = input('> ') -while(cmd != 'quit'): #Exits loop when user quits - if(cmd == 'feed'): - hunger -= 2 #Otto is fed, hunger decreases - happiness -= 1 #Otto is not pet, happiness decreases - elif(cmd == 'pet'): - happiness += 2 #Otto is pet, happiness increases - hunger += 1 #Otto is not fed, hunger increases - if(hunger > 5): #Otto is not fed enough - print(name + ' is hungry') - if(happiness < 5): #Otto is not pet enough - print(name + ' wants more attention') - elif(hunger <= 5 and happiness >= 5): #Otto is satisfied! - print(name + ' feels happy') - cmd = input('> ') #Keep taking user input until user quits - -# Feel free to customize your virtual pet by changing the how much the hunger and happiness variables increase and decrease, or add more actions! From 5f9af35861dcbafebebb46810360c04ee700758a Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:30:03 +0900 Subject: [PATCH 41/42] Update virtual_pet.py --- 1_beginner/chapter5/practice/virtual_pet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter5/practice/virtual_pet.py b/1_beginner/chapter5/practice/virtual_pet.py index 4c6dea22..04a7442f 100644 --- a/1_beginner/chapter5/practice/virtual_pet.py +++ b/1_beginner/chapter5/practice/virtual_pet.py @@ -1,4 +1,5 @@ """ +Virtual Pet Code a virtual pet! First, create three variables: name, hunger, and happiness. Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto') From 860f9c50caf42fc639984822395c0b32cf7f78d3 Mon Sep 17 00:00:00 2001 From: Nono <38902034+BitPupper@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:30:24 +0900 Subject: [PATCH 42/42] Update virtual_pet.py --- 1_beginner/chapter5/solutions/virtual_pet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/1_beginner/chapter5/solutions/virtual_pet.py b/1_beginner/chapter5/solutions/virtual_pet.py index c4f0c40d..13ea0c25 100644 --- a/1_beginner/chapter5/solutions/virtual_pet.py +++ b/1_beginner/chapter5/solutions/virtual_pet.py @@ -1,4 +1,5 @@ """ +Virtual Pet Code a virtual pet! First, create three variables: name, hunger, and happiness. Initialize hunger to 6 and happiness to 0, and set name to whatever you like. (e.g. 'Otto')