L8c L2 Arithmatic&Date Types
L8c L2 Arithmatic&Date Types
Date:
Data Types
We should remember from Year 7 work that when we use inputs we might have to set
different Data Types. When it comes to Data Types Python will automatically assumes the
data we input is a ‘string’ (a collection of keyboard characters) unless we instruct it
otherwise. But this may cause issues:
See below we have entered two decimal numbers, but python has just displayed them one
after the other. This is because of the default string setting.
Now if we set the data type to a decimal number (float) in our code and we get the result
we would expect, python has added up our two inputs.
It’s fairly simple to set up a data type. There are two main ways:
L8c_L2_Arithmatic&Data_Types
Student Name:
Date:
Today we are going to do some work with different data types by programming a range of
data calculations.
Note: A computer uses the following symbols to perform calculations, you will need these to
program python:
1. Using the codes above complete the challenges below. You need to look carefully at
the challenge as it will say which data type you need to include. Take a screenshot of
both your code, and the result when you run it:
Challenge 1:
Can you write a python program write a program that will allow the user to enter their
firstname then their surname as a string; then add them together to display them on one
line as an output?
Challenge 2:
Can you write a python program write a program that will store two whole number inputs
from the user and subtract one from the other, then display the result.
Challenge 3:
Can you write a python program write a program that will store two Decimal Number inputs
from the user and perform a multiplication, then display the result.
L8c_L2_Arithmatic&Data_Types
Student Name:
Date:
Extension’s:
Can you write a program that performs a calculation on 3 or more numbers? You can choose
if it is an integer or a decimal.
Can you write a program that performs a mixed calculation (addition, and subtraction; or
multiply and addition) on 3 or more numbers? Again you can choose if it is an integer or a
decimal.
L8c_L2_Arithmatic&Data_Types