Lesson Objectives:
Lesson Objectives:
To be able to:
- Create nested if statements
- Create lists
- Import modules
Programming: theory (8)
Give the data type for the following sample data and a brief description of what you will use that data type for:
|Sample data |Data type |Description |
|Concise | | |
|145 | | |
|7575790 | | |
|88.50 | | |
|True | | |
| | | |
Selection with IF (15 – 20)
Sometimes we only want a program to execute code under certain circumstances. We call
this selection. The most commonly used way of doing this is using if. Here we say if a
condition is true execute some code.
First we need to make sure we are happy with the condition. A boolean condition is one
that can have only two values true or false.
The boolean comparison operators are as follows:
|Operator |Meaning |
|== | |
|!= | |
|< | |
|> | |
|= | |
Use 3 operators from above to show an algorithm. What I would like you to do is show me 3 operators and how you would use them in python. Your program could be a very basic one or complex.
An example has been provided for you:
Name = “Bob”
If name ==”Bob”:
Print(“Hey Bob, where have you been hiding?”)
Note:
1. Make sure you are using the correct syntax
2. Don’t forget the colon : , (
3. Don’t forget the indentation
4. don’t forget the brackets
Programming
Task 1 (10)
We can store text in variables and we can then manipulate that text. To do this we use something called string method. I have put an example below, it is your job to try all of them and explain what they do and find other examples online.
Name = “Bob”
Print(Name.upper())
|String method |Description of what it does |
|lower() | |
|upper() | |
|title() | |
|swapcase() | |
|capitalize() | |
The output: BOB
Can you remember what concatenation is? If not, do a quick search online and make a note of it.
Task 2 - Restaurant Tip
Write a program.
Two people eat dinner at a restaurant and want to split the bill.
The total comes to £100 and they want to leave a 15% tip. How much should each person pay?
Harder: make the program ask how many people there are, what percentage the tip should be and how much the bill comes to.
Save this as Restaurant tip.
Help with the above:
1. Declare a variable called bill which should take the an input from the user “what is the total amount)
2. The variable bill should also convert the input into integer
3. Declare a variable called tip which should ask the user the amount they are going to tip
4. This variable should convert the string input into integer
5. Declare a variable called people which should ask the number of people there are at the table
6. Declare a variable called tip_amount which should be equal to bill multiplied by (tip divided by 100) >>>> Think about why we might do this
7. Declare total to be equal to bill plus ? what variable do we need here
8. declare per_person to be equal to total divided by people
9. print the statement to show the total and how much each person should pay
Task 3 – Exam grades
The grade boundaries for a test are:
U - 0
D – 40
C – 50
B – 60
A – 70
Write a program that asks for a mark and then says what grade it is worth.
For this, you will need to think about using elif statements.
Example: (Note you can make a lot of improvements to the program below)
grade = int(input("What did you get on the score?"))
if grade == 0:
print("You have failed")
elif grade == 40:
print("You have achieved a D")
Task 4 – hangman in python
Access the website and open the pdf document.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- objectives of financial management
- primary objectives of financial managers
- finance objectives examples
- educational objectives examples
- marketing objectives vs marketing strategy
- career objectives for direct care
- objectives for resumes in finance
- finance goals and objectives examples
- lesson objectives for reading comprehension
- lesson quiz lesson 2 the paleozoic era
- writing lesson plan objectives examples
- lesson outline lesson 2 pollution