Reference no: EM133059340 , Length: word count:300
Learning Activity: Programming Exercise
With this learning activity, you will learn how to read user's input and how to read Python official documentation.
First navigate to this small section on Python's official documentation: There is no programming class that can cover all features and its library of a programming language. You will need to learn to read the language's official documentation to how to get things done.
In this example, you will learn how to read in users' input from the keyboard. The built-in function to achieve that is the input() function. For now think about functions as some little helpers that take in some inputs, do something for you, and may also produce some outputs.
In the official documentation, it shows the syntax for the input() function is: input([prompt])
You can include some prompt message to guide users' input. For example, input(‘Please enter your age: '). The screen will output the prompt message then wait for user's input. This function returns the users' input as a string. Please refer to the example in the official documentation.
Now that you have learnt the input function, let's do exercise to put it in practice. Write a program in Python that asks the user to input the year they were born and outputs their age (approximately) using the current year minus the year they were born. HINT: you will need to convert users' input to an integer.
Sample input/output:
>>> Please enter the year you were born:
>>> 1991
>>> You will turn 30 in year 2021.
Post your implementation to the Module 1.2 Programming Exercise 1 discussion forum. Since this question asks you to write a program, lease upload your code as a Python code file (.py file) and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.
Attachment:- Programming Exercise.rar