Chapters
Python114 chapters

Exercises

User Input

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

The typed answer has stray spaces and capitals. Clean it up and print True when it means yes.

Python
answer = "  Yes \n"
# print True when the cleaned answer is y or yes
Exercise 2

The line holds two numbers separated by a space. Print their sum.

Python
line = "3 4"
# print the sum of the two numbers
Exercise 3

Return None for text that is not a whole number, and the number otherwise.

Python
def parse_age(text):
    # return the number, or None
    pass

print(parse_age("30"))
print(parse_age("thirty"))