Python-Functions-Assessment
Python-Functions-Assessment
Example Question
def CtoF(temp_in_C):
temp_in_F = temp_in_C*1.8 + 32
return temp_in_F
Question 1
Question 2
sum_between(start,end):
total = 0
for number in range(start,end):
total = total + number
return banana
Write a function called sum_between that finds the total of all numbers between two given
inputs.
For example
sum_between(1,10)
1+2+3+4+5+6+7+8+9+10 = 55
sum_between(20,25)
20+21+22+23+24+25 = 135
Question 3
def factorial():
total = 0
for i in range(1,n+1):
total = total*i
return total
For example
5! = 5x4x3x2x1
The function should take a single input parameter and output the factorial of that number.
Question 4
def positivity(numbers):
Write a function positivity that counts the number of positive numbers in a list of numbers.
The function should take a single input parameter, which will be a list.
The function should return a single integer, which is count of positive numbers.
The function has been started, but there is a missing line of code.
There are also at least two further errors in the code.
Question 5
Write a function which counts the number of even and odd numbers in a list of numbers.
The function should return a list containing 2 numbers. The number of odds should be first
and the number of evens should be second.
Question 6
Write a function that finds the average test score from a list of test scores.
Question 7
Write a function that takes a list of integers and double each number in the list.
Question 8
Write a function that counts the number of times that a particular character appears in a
string.
For example "i" appears in the string "I am going to be happy." 2 times.
The function should take 2 input parameters - first a string, second a single character.
Question 9
Write a function which removes all of the vowels from a piece of writing.
Question 10
Bonus Question
You should only attempt this if you have attempted all of the other problems.