Watch the video and take notes, pay attention to how data is input and assigned to variables.
Run and walk through the example (in code window).
Read the task and write code to solve.
Make a note of successful code in your book.
Answer questions in your book.
Watch the video and create notes in order to be able able to apply the knowledge given.
# Example code (Input command)
wholeNumber = int(input("Enter a whole number"))
print("Your number was",wholeNumber)
decimalNumber = float(input("Enter a decimal number"))
print("Your number was",decimalNumber)
word = str(input("Enter a word"))
print("Your word was",word)
# A character would be just represented as the input of a single character using the above str data type.
# You can input Boolean data however it is only ever True or False.
Apply your knowledge and write a program that will ask for a users first name, surname, age and height in metres (e.g. 1.5 metres). The program with then print out the information in a sensible form.
Input first name, surname, age, height from a user (using the correct data type)
Output data in a sensible form (Construct a sentence with data)
name = str(input("Enter your first name :"))
surname = str(input("Enter your surname :"))
age = int(input("Enter your age :"))
height = float(input("Enter your height in metres :"))
print(name, surname, "is",age,"years old and",height,"metres tall")
Identify the associated data type and give an example of how they could be used in a program:
int
float
str
Describe why we use variables when inputting data from a user.
Describe what might happen if the user enters the wrong data when asked to input from a keyboard. (inputs "a" instead of 16 for age.)
Identify and describe each part of the following Python instruction
number = int ( input ( "Enter a number :" ) )
Indentify the associated data type and give an example of how they could be used in a program:
int
float
str
int = integer, a whole number that can be used in a program to collect any of the following: age, house number, marks in a test, etc.
float = float, a decimal number that can be used to represent real numbers (numbers with a decimal point). A program could use a decimal number of any of the following reasons: measurements of size, capacity, volume, accurate numbers, etc.
str = string, a collection of characters stored between "quotation marks", a program could use a string data type for any of the following reasons: textual information meant to be displayed to a user like a name, etc.
Describe why we use variables when inputting data from a user.
Variables when used with input commands, the input command takes the users data from the keyboard and directly stores it in the variable to be used later in the program. A calculator needs to hold two numbers before it can complete the calculation.
Describe what might happen if the user enters the wrong data when asked to input from a keyboard. (inputs "a" instead of 16 for age.)
If a user input a string when an integer was required an error will occur, if a user inputs an integer when a string is required it will convert it to a non mathematical shape/letter.
Identify and describe each part of the following Python instruction
number = int ( input ( "Enter a number :" ) )
Variable is assigned to an integer input collected from the keyboard when the user is asked "Enter a number :"