Vous êtes sur la page 1sur 2

Assignment for Function (Individual Assignments)

1. What does the following piece of code display when run — and why?

f = 0
k = 0

def f2k(f):
k = ((f-32)*(5.0/9.0)) + 273.15
return k

f2k(8)
f2k(41)
f2k(32)

print(k)

Answer: Because the calculation is not involving k, so it will not print the result.
2. Write a loop that counts the number of vowels in a character string.Test it on a few individual
words and full sentences. Once you are done, compare your solution to your neighbor’s. Did you
make the same decisions about how to handle the letter ‘y’ (which some people think is a vowel, and
some do not)? Complete the following code

vowels = 'aeiouAEIOU'
sentence = 'Mary had a little lamb.'
count = 0
for char in sentence:

______________________

______________________

______________________

Answer:

Vous aimerez peut-être aussi