Monday 27 June 2016

AQA GCSE - Variables

Lesson Objectives
To identify the variables needed for your work. To create code that will assign values to these variables

Starter
If you need a recap on variables, Check out this BBC Bitesize resource:
How do computer programs use variables? http://goo.gl/Kh0xtG



Red Task – Identify the variables
  1. Read through Task 2 on page 5 of your booklet carefully to identify the 8 variables
  2. Underline or highlight all of the variables you can find
  3. Add each item to the ‘Information to store’ column in the table on Page 2 of your sheet



Amber Task – Name the variables
  • Python variables should be written in lowercase
  • Each word should be separated by an underscore (_) character
  • Descriptive and meaningful names should be used, for example:
fruit_apple = 1
fruit_banana = 2
fruit_kiwi = 3
  1. Choose a sensible and logical variable name for each piece of information that you identified in the previous task
  2. Add each variable name to the ‘Variable name’ column in the table on Page 2 of your sheet.

Green Task – int OR float
In Python, a number can either be stored as an int or a float, for example:
num_a = 1    # int
num_b = 1.5  # float
If the number contains a decimal value (like 1.5) it’s float. If not, it’s an int.
  1. Which of the variables need to be stored as int?
  2. Which of the variables need to be stored as float?
  3. Complete the ‘int OR float’ column of the table below:


Information to store

Variable name

int OR float

































Examples
To store an int:
print("Please enter int:")
num_a = int(input())  # e.g. 1


To store a float:
print("Please enter float:")
num_b = float(input())  # e.g. 1.5


Controlled Assessment Task
Develop the part of the program that allows the user to set the Generation 0 values for the:
  • population numbers of juveniles, adults and seniles
  • survival rates for juveniles, adults and seniles
  • birth rate
  • number of new generations to model. This should be between 5 and 25.
The program should then return to the menu.


Use what you have learnt in this lesson to complete Task 2 of the controlled assessment


  1. Open your CA_Task1 file from last lesson
  2. Save a copy of the file (Save As…) as CA_Task2
  3. Declare your variables at the top of the file
  4. Below the code 'if choice == 1:', use print() statements to ask the user to enter the values, one by one
  5. Store each value into a variable using the input() function
  6. Convert each value into either an int() OR a float()
  7. Add plenty of # comments to explain your code
  8. Run your program to check that it works

Extension Tasks
1. Can you reduce your code to assign variable values using less code? See example below:
num_a = int(input("Please enter int:"))

2. Can you use Validation to check the input value is within the accepted range?


No comments:

Post a Comment