Learning IntentionsTBAT - Use intergers and strings to write clear readable code that will create a working calculation.
Success CriteriaYou will create a simple maths calculation to work out the area of a rectangle.
Completing the extended activity will mean you have added inputs and comments to your script. |
Keywords
|
Starter Activity
Click on the button to take you to the quiz page and test out your knowledge of Units of data
|
You already know that you can use Python as a calculator and that the arithmetic operators we use to do this are:
+ addition
- subtraction
* multiplication
/ division
Open the Python Shell ( Interactive mode) then open a "New window" (script mode) type in the following calculations:
+ addition
- subtraction
* multiplication
/ division
Open the Python Shell ( Interactive mode) then open a "New window" (script mode) type in the following calculations:
Save the script as "simple_calculation.py" then run it (F5)
If you done things correctly you should see the answers to the calculations in the shell. Check with the image below.
If you done things correctly you should see the answers to the calculations in the shell. Check with the image below.
We can put the results of calculations into variables. These variables will not be a string but an integer (whole numbers) or float (decimal). Try out this next script, save it as "Simple_intergers.py" then run it (F5)
Time to try it out for yourself
Complete this program so it uses addition on the two variables ( a and b) making c equal to 15 then prints out the answer to screen.
a=7
b=8
c=
a=7
b=8
c=
Moving on
We will now work together on the next stage which is Data Types |
Copy the following code then, save as "data_types.py" and run
a=input ( "Enter number 1:" )
b=input ( "Enter number 2:" )
c=a+b
print ( "Adding your number together gives: " +c )
a=input ( "Enter number 1:" )
b=input ( "Enter number 2:" )
c=a+b
print ( "Adding your number together gives: " +c )
What happend and why?
Try this new code, save it as "data_typesV2.py" this time
a = int(input('Enter number 1:'))
b = int(input('Enter number 2:'))
c=a+b
print ('Adding your numbers together gives:'+c)
a = int(input('Enter number 1:'))
b = int(input('Enter number 2:'))
c=a+b
print ('Adding your numbers together gives:'+c)
Can we find a solution - YES WE CAN - try this amended code
a = int ( input('Enter number 1:'))
b = int ( input('Enter number 2:'))
c=a+b
print ('Adding your numbers together gives:'+str(c))
b = int ( input('Enter number 2:'))
c=a+b
print ('Adding your numbers together gives:'+str(c))
Independant task
Code 1 - Write a program that asks for a length and width and outputs the area of
a rectangle E.g. Please enter width: Please enter height: The area is: |
Code 2 - Add a "Header "comment that tells us who the creator of the code is and its function. Next add comments to your code that explain what each line is doing and what the user should expect to see if it runs correctly.
|
WWW - EBI
Add your www & ebi comments to this blog - you should celebrate your success and if you overcame any problems please share this with the group. If you would like cover this topic again or have any problems that you still would like some help with please share this too so that I can think of ways to improve our lessons in the future.
Lets's Blog
Lets's Blog