Q1. In pairs, take another look at the two screenshots of the Scratch and IDLE coding environments above. Identify what is similar and what is different. Copy and complete the table, adding as many similarities and differences as you can between the two types of programming language.
Ans: Similarities:
Differences:
Scratch:
IDLE (Integrated Development and Learning Environment):
Q1. Open the Python IDLE. The Python shell will open as shown here:
Enter this command at the interactive prompt(>») and press ENTER:
print("Welcome to the Python Shell")
Now enter a command to print your name onto the screen and press ENTER:
print("Type your name here")
Now try this command:
print("Hello World)
An error should occur because you have left out a set of quotation marks.
Correct the error and execute the command again.
Ans:
print("Welcome to the Python Shell")
and press ENTER, the Python Shell will display the message: Welcome to the Python Shell.print("John Doe")
.print("Hello World)
is missing a closing quotation mark. To correct it, add the missing quotation mark so it reads print("Hello World")
.
Q2. Try entering this calculation:
(7+3*2
Look at what has happened this time. Why do think this is?
Correct the error and execute the command again. The answer should be 20.
Ans:
(7+3*2
is missing a closing parenthesis. This causes a syntax error because every opening parenthesis needs a matching closing parenthesis.(7+3*2)
. The correct calculation should be 7 + (3 * 2)
to get the answer 20, because according to the order of operations, multiplication is done before addition.result = (150 + 23) * 3
print(result)
When you run this command, Python will display the result: 519.
And here are four additional math commands you can try:
Q1. Open Python IDLE.
- From the Python shell, select 'File'.
- Then select 'New File'.
- Enter the following code on line 1:
print("Welcome to my first program in Python")
- Now enter a command to print your favourite hobby onto the screen
print("Add favourite hobby")
- Save your program. Call it 'My First Program'.
- Run the program and make sure it works correctly.
Ans:
Q2. Now add the following programming code to your program:
print("Did you know Python can do calculations? The line of code below
will display the number 10 11 )
print(7+3)
print("How about this? The calculation below should display the number 25")
print(7+3*2+5)
- Run the code. There should be an error that has occurred; can you correct the error
so that the program runs?
- The final number doesn't give the correct answer; it says 18 instead of 25. Correct
the error and run the program again.
- Add a comment on your programming code above the line you have just corrected
explaining why it didn't work correctly to begin with.
Ans:
And here’s the comment explaining the initial error:
# The initial calculation did not give the correct answer because it did not take into account the order of operations, also known as PEMDAS (Parentheses, Exponents, Multiplication and Division, Addition and Subtraction). Without parentheses, multiplication is performed before addition, leading to an incorrect result.
Q3. Create a new program in IDLE and save the program, calling it 'Maths Favourites'.
- Add code so that it prints out three different pieces of information; it should display
your name, your favourite number and your favourite type of calculation, for
example addition. An example of what your program could look like is shown below:
Name : Adnan
Favourite number: 7
Favourite calculation: multiplication
- Save and run your file.
Q1. Open the Python IDLE.
- From the Python shell, select 'File'.
- Then select 'New File'.
- Type the following code:
name = "Ardeel"
age= 12
address= "Station Road"
colour= "Red"
print("Your name is",name)
- Now add the following code, so it displays the age:
print("You are",age, "years old")
- Complete the program by getting it to say:
- 'You live at' and then the address
- The colour and then 'is your favourite colour'.
- The finished program should look like this :
Your name is Ardeel
You are 12 years old
You live at Station Road
Red is your favourite colour
When you run this program in Python IDLE, it will display:
Your name is Ardeel
You are 12 years old
You live at Station Road
Red is your favourite colour
Q2. Create a new program that shows your name, age, address and favourite colour. Save and run your file.
Q1. Below are two different programs in Scratch. Rewrite each of these programs in Python.
Ans: Program 1:
Program 2:
Q2. Create a new program in Python that:
- asks the user to 'Enter your name' and stores it in a variable called name
- asks the user to 'Enter a number between 1 and 10' and stores it in a variable called number
- uses print to create an output that looks something like this when run:
Enter your name Khalil
Enter a number between land 10 6
Your name is Khalil and the number you entered was 6
Run your program to check for errors.
Pair up with another student and review their solution. Check that the print message is in the same format as the example above.
Ans:
Q1. Look at the Python code below. It shows a number of variables storing different pieces of data:
name = "Maryam"
cardNumber = " 00125639 430298 45"
balance = 145 . 98
address = "Mall Road"
age = 11
Copy and complete the table below, identifying the data type for each variable and giving an explanation of the data type you have
chosen.
Ans:
Q2. Open the DataTypes.py provided by your teacher.
Edit the code and finish the program so when it is run it looks like this:
Name : Maryam
Age : 13
Address : Station Road
Bank Car d Number : 0012563943029845
Current Balance : 145.98
Ans:
Q1. Open the file MealCost.py provided by your teacher:
money = input (" How much money do you have? ")
meal = input ( ''How much did t he meal cost? " )
left = money - meal
print ("After your meal you have ," , lef t , '' left")
- Run the program; you will see it contains errors.
- Make changes to the code so that the inputs are cast to the correct data type and the program runs.
Ans: The MealCost.py program you’ve provided is attempting to perform arithmetic with strings, which will cause an error because Python expects numbers for subtraction. To fix this, you need to convert the inputs to a numerical data type before performing the subtraction. Here’s the corrected code:
Q2. A rabbit's age is approximately nine times the age of a human. Create a new program in Python using the Scratch program solution below, which calculates the age of a rabbit in rabbit years:
Ans:
Q3. Create a new program in Python that:
- asks the user to "Enter the length of one side of a square" and stores it in a variable called length; this should be cast as an integer
- calculates the area of the square (HINT: this is the length multiplied by the length)
- uses print to create an output; an example is given below:
Enter the length of one side of a square : 7
The area of the square is: 49
Ans:
Q4. Create a new program in Python that calculates the speed of a moving car. The program should:
- ask the user to enter the distance in meters; this should be cast to an integer
- ask the user for the journey time in seconds; this should be cast to an integer
- calculate the speed; this is the distance divided by time
- use print to output the speed; an example is given below:
Enter the distance in meters : 15 00
Enter the time in seconds : 40
The car was travelling at a speed of 37 . 5 meters per second
Ans:
Q1. Predict the outcome of the flowchart on page 26 if the following values are entered:
- number1 = 15, number2 = 20
- number1 = 9, number2 = 17
- number1 = 45, number 2 = 36
Ans:
number1 = 15, number2 = 20
, the outcome would be 35
.number1 = 9, number2 = 17
, the outcome would be 26
.number1 = 45, number2 = 36
, the outcome would be 81
.Q2. Were your predictions correct?
Open the file BasicAddition.py provided by your teacher.
Enter the values above into your program. Are the answers the same as your predictions?
Ans: Yes
Q3. Using the correct symbols, create an algorithm using a flowchart that does the following:
Asks the user to input two numbers
Adds the two numbers together and then divides by 2 to find the mean average
- Outputs the average.
Try coding your flowchart in a new Python program.
Ans:
Q4. Evaluate your flowchart and Python program. Ask a partner to check your flowchart with the following values. Do they get the correct output?
— number1 = 7, number 2 9; average should be 8
number1 = 15, number2 = 20; average should be 17.5
Ans:
number1 = 7, number2 = 9
, the average should indeed be 8
.number1 = 15, number2 = 20
, the average should be 17.5
.Q1. Open IDLE and use Python in interactive mode.
Copy and complete the table below and enter the different calculations into Python as they are written in the left-hand
column. For each calculation, record the answer that is given. Now change the calculation using BIDMAS until you get the
answer in the desired answer column. The first one has been done for you as an example.
Calculation | Answer | Desired Answer | Calculation to get desired answer |
5 * 8+ 6 | 46 | 70 | 5 * (8 + 6) = 5 * 14 = 70 |
35-10+15 | 40 | 10 | (35 - 10) - 15 = 25 - 15 = 10 |
19 + 31 * 5 | 174 | 60 | (19 + 31) * 5 / 25 = 50 * 5 / 25 = 10 * 5 = 50 |
9 * 8- 20 I 5 | 68 | 10.4 |
|
60*40 - 3*4 | 2376 | 8880 | |
18 * 6-2 /8 | 107.75 | 9 | (18 * 6) / (2 / 8) = 108 / 0.25 = 432 |
Q1. Open the file ProductCost.py provided by your teacher.
price = input ( "Enter the product price :)
quantity = input ("Enter the product quantity:)
cost = price + quantity
print ("The total cost is: "+ total)
There are a number of errors in the code that prevent the program working.
The program should:
ask the user to enter a price and a quantity
- calculate the cost (price multiplied by quantity)
display the overall cost.
Work through the code line by line to identify and debug the errors.
Open the file Product Cost Test Plan.docx provided by your teacher. Apply the test plan to the file ProductCost.py to ensure that your amended program works correctly.
Ans:
Errors corrected:
input
functions.float
for price and int
for quantity).cost
to total_cost
to match the print statement.+
from the print statement, as it’s not needed when using commas.total
to total_cost
in the print statement to match the variable name.Q2. You now have the opportunity to sabotage a program! In pairs, one person should open NumberTrick.py and the other RestaurantBill.py provided by your teacher. The programs you have been given are fully working. Your task is to create five errors. Once you have sabotaged the program, swap programs with your partner and see whether they can identify and debug the program.
This is what the two programs should do when fully working:
Program 1
This program should complete a number trick where the result is always the number 3.
It should: ask the user to input a number double the number entered then add six to it then halve it then subtract the number the user started with and finally display the result.
Program 2
This program should calculate the amount each person should pay for a bill at a restaurant. It should:
ask the user to input the total bill
ask the user to input the number of people eating
calculate the tip: 15% of the total bill
calculate the total bill including the tip
work out the amount each person has to pay (the total including the tip divided by the number Of people)
display the amount each person has to pay.
Open the file Sabotage Test Plan.docx provided by your teacher. Apply the relevant test plan to the program you have just fixed to see whether it works correctly.
Ans:
For the sabotage task, here are examples of errors you could introduce into the programs:
NumberTrick.py (Program 1) Errors:
RestaurantBill.py (Program 2) Errors:
//
) instead of float division (/
) for the tip calculation.After introducing the errors, swap the programs with your partner and attempt to debug them. Once fixed, use the Sabotage Test Plan.docx
to check if the programs are working as intended.
Q1. Look at this Scratch example. When a number is squared (multiplied by itself), it is considered to be a 'Big Number' if it is greater than 100. Create a flowchart for this program.
Ans:
Creating a flowchart for the given Scratch program would involve the following steps:
number
).squared = number * number
).Q2. The alphabet used in English-speaking countries has 26 letters in it. Create a flowchart that asks for the number of letters in the English alphabet to be entered. If the number entered is 26 then it should display 'correct'; if it is not it should display 'incorrect'.
Ans:
Q3. Create a flowchart that satisfies the following criteria:
- The user is asked to enter two numbers.
- The flowchart checks to see whether the first number is greater than the second number.
- If it is, then it should output the sum of the two numbers.
- If it is not, it should output the difference between the two numbers.
Ans:
Q1. Combine all of your Python skills to create a working program for a different scenario:
Create a program in Python that contains a series Of questions.
At the end of the program it should output all of the different answers in a single sentence.
In addition, any of the answers that contained numbers should be added together and displayed at the end as the 'star' number
The program needs to ask the following questions:
What is your name?
What is your favourite colour?
How many days are there in a week?
How many seconds are there in an hour?
What is your favourite hobby?
How many days are there in a year (not a leap year)?
Ans:
Complete the following tasks:
Q1. Addition:
Create a flowchart that:
asks the user to enter two numbers
calculates the total by adding the two numbers together
outputs the answer.
Write the code for your flowchart in Python.
Ans:
Q2. Subtraction, multiplication and division:
Open the file FinalProjectSubtract.py provided by your teacher. Add comments using # to identify the data type for each variable and explain why you have chosen that data type.
- Edit the code so that it now multiplies the numbers instead of subtracting. Use the correct arithmetic operator to calculate the answer.
- Save this file and test it.
Edit the code and create another variable called divide that stores num1 divided by num2 . Add another print statement to output the answer.
- Save the file and test that it works .
Ans:
Q3. Area of a square:
Open the file FinalProjectSquareArea.py provided by your teacher.
Identify the error. Debug the code so that the program:
- asks the user to enter the length of one side of the square
- calculates the area by multiplying the length by the length
- outputs the answer.
- Save the file and test it.
Ans:
Q4. Area of a triangle:
- Look at this flowchart. The current flowchart:
- asks the user to enter the base and the height of the triangle
- calculates the area; this is half the base multiplied by the height
- outputs the answer.
- Edit the flowchart so it checks to see whether the area is greater than 50.
If it is, it should say 'big triangle'; if it isn't, it should say 'small triangle'.
Open the file FinalProjectTriangleArea.py. There is an error. Identify the error and debug it so that the program does what is described above.
- Save the file and test it.
Ans:
Q5. Perimeter of a rectangle:
- Create a program in Python that calculates the perimeter of a rectangle. The program should:
— ask the user to enter the length and width Of the rectangle
- calculate the perimeter; this is two multiplied by the length plus width
— output the answer.
— Write the code for your program.
— Save the file and test it by applying the test plan below:
Test number | test data | expected outcome | actual outcome | pass/fail |
1 | width = 8.5 | perimeter: 39 | ||
2 | width = 4.9 | perimeter: 28.2 | ||
3 | width = 3.4 | perimeter: 19 |
Ans:
Q6. Average of three numbers:
- This shows the Scratch solution to calculate the average of three numbers:
- Create this program in Python to perform the same task.
Ans:
28 videos|17 docs|5 tests
|
1. What are the differences between Scratch and Python programming languages? |
2. How can Python IDLE be used in Script mode for programming? |
3. What are some common data types in Python, and how can they be manipulated? |
4. How does Python handle error detection and correction in programming? |
5. How can flowcharts and algorithms be used in Python programming to improve code efficiency? |
|
Explore Courses for Class 6 exam
|