Given a string variable of a sentence. Write a function with two parameters, return the number of target character in the string.
Input:
string = 'Practice makes perfect'
Write a function
def character_counter(string, char):
counter = 0
# process the string to count character
return counter
Output:
print(character_counter(string, 'p')) # returns 2
Solution 1:
character_counter(string, char)
counter = 0
Solution 2:
Solve it with list comprihension.
len()
Given a list of lists, each list has two items, first item is age and second item is grade.
age < 15 and grade < 9 | Junior | |
age < 15 and grade < 9 | Junior | |
age > 15 and grade > 9 | Senior | |
age > 15 and grade > 9 | Senior | |
age < 15 and grade < 9 | Junior |
Write a function to categorize students info.
Input:
data = [[10, 4], [11, 5], [16, 10], [17, 11], [9, 3]]
Output:
['Junior', 'Junior', 'Senior', 'Senior', 'Junior']
Solution 1:
Solution 2:
Figure out a solution in list comprihension.
Write a function to print multiplication table in following pattern.
Hint
Try nested for loops
Homework: Return factorial of 10
Factorial is the product of all positive integers less than or equal to N. In our case N = 10, therefore, the result is 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 3628800
Write a function to return the factorial of 10.
How many solutions do you have?
You are encouraged to figure out the easiest solution.