Skip to content

Commit 6fb83fa

Browse files
Priyanka KarunakaranPriyanka Karunakaran
authored andcommitted
adding Ch. 14 practice and solutions
1 parent 6262900 commit 6fb83fa

18 files changed

+219
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#Problem name: add_10
3+
#A messy teacher named Bob would like to add 10 points to each student’s recent test score.
4+
#There are four students, and going from highest score to lowest score, it is Mike, Dan, Stan, and Ban.
5+
#Add 10 to each score and assign those values to the correct student.
6+
#Solve this problem by adding no more than 2 lines of code.
7+
#Hint: Use tuple unpacking and list comprehension.
8+
9+
#the scores are given
10+
scores = (100, 90, 80, 70)
11+
12+
#write your code below
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Problem Name: bob_selection
2+
3+
#Bob is choosing a person to go to the moon with him. The way he chooses is quite strange. He will choose the first person from a list given to him whose age is divisible by 5 and whose index within the list is divisible by 5. If he does find such a person, print the person’s name. If he doesn’t, don’t print anything. The list given to him contains lists which contain the person’s name and age. Use enumerate to solve this problem.
4+
5+
#the list is given to him
6+
people_list = [(“Ana”, 22), (“Mark”, 41), (“Dan”, 10), (“Jack”, 14), (“Ben”, 51), (“Jorge”, 65)]
7+
8+
#write your code below
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Problem Name: darwin_raccoon
2+
3+
#Darwin is observing raccoons’ growths on an unnamed island. He spends 7 days in total on this island, and on every day, he would record the average growth of raccoons in inches. He loses data on day 7, so he decides to make the data on that day to be the maximum of the previous 6 days. He needs to make a dictionary for use later where the key is the day number and the value is the average growth of raccoons on that day. You help him make the dictionary. Use zip to solve this problem.
4+
5+
#the lists are already given to you
6+
days_list = [“Day 1”, “Day 2”, “Day 3”, “Day 4”, “Day 5”, “Day 6”, “Day 7”]
7+
growths_list = [1.4, 2.1, 1.3, 0.1, 0.4, 1.9]
8+
9+
#write your code below
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Problem name: even_words
2+
#Given a string that the user inputs create a list that contains the square of the lengths of words with an even amount of characters.
3+
#For example, if the string is “I am cool”, the list would be [4, 16].
4+
#Use a list comprehension to solve it.
5+
6+
#the user inputs the string
7+
string = input()
8+
9+
#write your code below
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Problem name: odd_squares
2+
#Given a list of integers, create a list of all the squares of the odd integers within the list.
3+
#Use a list comprehension to solve it.
4+
5+
#the given code takes an input and makes it a list of numbers
6+
#for example, entering “1 23 4” as the input will result in the list [1,23,4]
7+
ex_list = input().split()
8+
for idx in range(len(ex_list)):
9+
ex_list[idx] = int(ex_list[idx])
10+
11+
#write your code below
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Problem Name: pokemon_presentation
2+
3+
Youre a teacher giving a presentation on the types(https://pokemon.fandom.com/wiki/Types) of pokemons(https://www.pokemon.com/us/pokedex/). You have a list pokemons_list, and you have another list types_list(this has the types of the pokemons in pokemons_lists in the same order). Since you are presenting, print “[insert pokemon] is a [insert type] typefor all the pokemons in pokemons_list with their corresponding types in types_list. Use zip to solve this problem.
4+
5+
#the lists are already given to you
6+
pokemons_list = [“Charmander”, “Squirtle”, “Bulbasaur”, “Pikachu”]
7+
types_list = [“Fire”, “Water”, “Grass and Poison”, “Electric” ]
8+
9+
#write your code below
10+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
#Problem Name: square_root_list
2+
#Take a user given list of numbers and make a list of all the square roots of the numbers using list comprehension.
3+
#Use a list comprehension to solve it.
4+
#Hint: The square root of a number is the same as taking the ½ power of a number.
15

2-
"""
3-
Problem Name: square_root_list
4-
Take a user given list of numbers and make a list of all the square roots of the numbers using list comprehension. Use a list comprehension to solve it. Hint: The square root of a number is the same as taking the ½ power of a number.
56
#the given code takes an input and makes it a list of numbers
67
#for example, entering “1 23 4” as the input will result in the list [1,23,4]
78
ex_list = input().split()
89
for idx in range(len(ex_list)):
910
ex_list[idx] = int(ex_list[idx])
10-
"""
1111

1212
#write your code below
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#Problem name: update_score
3+
#A hacker named Dan wishes to hack into a competition where they judge participants in three categories on a scale of 10.
4+
#Dan wants his friend Bob to win.
5+
#Bob will only win if he has all 10s while the other competitors, Jo and Stan, don’t.
6+
7+
#Judges will store the scoring within a tuple ([...], [...], [...]).
8+
#The scores before Dan hacked are given.
9+
#Bob will be located as the first person the judges scored and will have the lowest points out of any participant.
10+
#Create a program to help Dan help Bob win.
11+
#Also, print Bob’s score at the end.
12+
#Use tuple unpacking to solve this problem.
13+
14+
#the scores are given
15+
scores = ([1,1,1] , [2,2,2], [3,3,3])
16+
17+
#write your code below
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Problem Name: worried_josh
2+
3+
#Josh is worried about his test score. He wants to score in the top n, where n is a positive integer that the user inputs. Given a list of student names where the student with the highest score is the 0th index and the score goes down from there, print “YES!” if Josh scores in the top n, and “NO :(“ if he doesn’t. Assume n will not be greater than the number of students. Use enumerate to solve this problem.
4+
5+
6+
#the list of student names is given and the n is a user input
7+
#remember the leftmost student has the highest score whereas the rightmost has the lowest score
8+
students = [“Dan”, “Sherlocks”, “Jo”, “Josh”, “Dennis”, “Erwin”, “Ivan”, “Penny”]
9+
n = int(input())
10+
11+
#write your code below
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#Problem name: add_10
3+
#A messy teacher named Bob would like to add 10 points to each student’s recent test score.
4+
#There are four students, and going from highest score to lowest score, it is Mike, Dan, Stan, and Ban.
5+
#Add 10 to each score and assign those values to the correct student.
6+
#Solve this problem by adding no more than 2 lines of code.
7+
#Hint: Use tuple unpacking and list comprehension.
8+
9+
#the scores are given
10+
scores = (100, 90, 80, 70)
11+
12+
#write your code below
13+
scores_added = [n + 10 for n in scores]
14+
Mike, Dan, Stan, Ban = scores_added

0 commit comments

Comments
 (0)