Python Functions Assessment Answers
Python Functions Assessment Answers
def FtoC(F):
return (F-32)/1.8
#Question 2
def sum_between(start,end):
total = 0
for number in range(start,end+1):
total = total + number
return total
#Question 3
def factorial(n):
total = 1
for i in range(1,n+1):
total = total*i
return total
#Question 4
def positivity(numbers):
#Question 5
def odd_or_even(numbers):
odds = 0
evens = 0
for num in numbers:
if num%2==0:
evens+=1
else:
odds+=1
return [odds,evens]
#Question 6
def ave_test_score(scores):
total = 0
for score in scores:
total+=score
return total/len(scores)
#Question 7
def doubler(numbers):
new_numbers=[]
for num in numbers:
double_num = 2*num
new_numbers.append(double_num)
return new_numbers
#Question 8
def character_counter(text,char):
text = text.upper()
char = char.upper()
return text.count(char)
#Question 9
def the_Kiwi_translator(text):
new_text = ""
for char in text:
if char.upper() not in "AEIOU":
new_text+=char
return new_text
#Question 10
def digits_sum(number):
number = str(number)
total = 0
for n in number:
total+=int(n)
return total
#Bonus Question
def digit_sum(number):
number = str(number)
final_total = 10
while final_total>=10:
total = 0
for n in number:
total+=int(n)
number = str(total)
final_total = total
return final_total