Hands On Exercise
We'll cover the following
Congratulations on completing the lesson on Python I/O. Test your knowledge through these short snippets and get one step closer to mastering Python!
Exercise 1
Suppose you have to input the year of birth from a user and save it in a variable called birth_year. Fill in the blank below to take a valid input without adding any prompt. Once you’ve added your changes, run the code to see the output and compare it with the solution.
birth_year = _______
Exercise 2
This time, give the user a prompt that says “Enter your birth year here:”. Be sure to also convert the input obtained to a suitable data type and save it in a variable called birth_year_converted. Once you’ve added your changes, run the code to see the output and compare it with the solution.
birth_year = _______birth_year_converted = _______
Exercise 3
Suppose we have a variable named “accuracy” with a value of 98.43138921. Print “accuracy” such that it is only displayed to 3 decimal places.
accuracy = 98.43138921_______