Class 6 Exam  >  Class 6 Notes  >  IGCSE Cambridge Computing for Year 6  >  Textbook Solutions: Block it out: Moving from blocks to text

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6 PDF Download

Comparing Scratch and Python

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:

  • Both are programming environments used to write, test, and debug code.
  • They allow for the creation and execution of programs.
  • Both provide a user interface to interact with the code.

Differences:

  • Scratch:

    • Designed for beginners and young learners.
    • Uses a block-based programming approach, which means you drag and drop blocks that represent code commands.
    • It’s more visually oriented and allows for easy understanding of programming concepts without writing syntax.
    • Great for interactive stories, games, and animations.
  • IDLE (Integrated Development and Learning Environment):

    • It’s a text-based environment, which means you type out the code in text form.
    • Used for Python programming and is suitable for both beginners and experienced programmers.
    • It requires understanding of syntax and text-based commands.
    • More suitable for creating scripts, automation, and complex programs.

Using Python

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: 

  1. When you enter print("Welcome to the Python Shell") and press ENTER, the Python Shell will display the message: Welcome to the Python Shell.
  2. To print your name, replace “Type your name here” with your actual name. For example: print("John Doe").
  3. The command 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.

  • Try entering four of your own maths commands. Remember that the * (star symbol) is used for multiplying.
  • Get Python to add 150 and 23 together and then multiply the result by 3.

Ans: 

  1. The calculation (7+3*2 is missing a closing parenthesis. This causes a syntax error because every opening parenthesis needs a matching closing parenthesis.
  2. To correct it, add the missing 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.
  3. Here’s how you can get Python to add 150 and 23 together and then multiply the result by 3:
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:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Using Python IDLE in Script mode

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6


Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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.

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Variables

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

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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.

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Adding more information to a program

Q1. Below are two different programs in Scratch. Rewrite each of these programs in Python.
Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Ans: Program 1:Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Program 2: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Data types - string, integer and real

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: 

Variable NameDatatypeExplanation
namestrThe str datatype represents a string, which is a sequence of characters used to store text.
cardNumberstrAlthough it contains numbers, cardNumber is stored as a str because it includes spaces and is not used for arithmetic.
balancefloatfloat stands for floating-point number, which is used to store decimal values.
addressstrSimilar to name, address is a sequence of characters including spaces, hence it is a str.
ageintThe int datatype represents an integer, which is a whole number without a decimal point.


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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Casting

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:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Ans:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Flowcharts and algorithms

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: 

  • For number1 = 15, number2 = 20, the outcome would be 35.
  • For number1 = 9, number2 = 17, the outcome would be 26.
  • For 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:
Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: 

  • For number1 = 7, number2 = 9, the average should indeed be 8.
  • For number1 = 15, number2 = 20, the average should be 17.5.

BIDMAS in Python

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.

CalculationAnswerDesired AnswerCalculation to get desired answer
5 * 8+ 646

70

5 * (8 + 6) = 5 * 14 = 70 
35-10+1540

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 568

10.4

(9 * 8) / (20 / 5) = 72 / 4 = 18

60*40 - 3*423768880
18 * 6-2 /8107.759(18 * 6) / (2 / 8) = 108 / 0.25 = 432 


Error detection and correction

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Errors corrected:

  • Added missing closing quotes in the input functions.
  • Cast the inputs to the correct data types (float for price and int for quantity).
  • Changed the variable name from cost to total_cost to match the print statement.
  • Removed the + from the print statement, as it’s not needed when using commas.
  • Changed 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:

  1. Remove the multiplication by 2, so it only adds 6.
  2. Change the addition of 6 to subtraction.
  3. Forget to halve the number.
  4. Subtract a different number instead of the one the user started with.
  5. Print the wrong variable at the end.

RestaurantBill.py (Program 2) Errors:

  1. Set the tip to a wrong percentage, like 50%.
  2. Forget to add the tip to the total bill.
  3. Divide by the wrong number of people (e.g., a hardcoded number).
  4. Use integer division (//) instead of float division (/) for the tip calculation.
  5. Print a message that doesn’t include the calculated amount each person has to pay.

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.


Making choices IF THEN ELSE in flowcharts

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.
Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Ans: 

Creating a flowchart for the given Scratch program would involve the following steps:

  1. Start: Begin the flowchart.
  2. Input: Ask for a number (let’s call it number).
  3. Process: Square the number (squared = number * number).
  4. Decision: Check if the squared number is greater than 100.
    • If Yes, go to step 5.
    • If No, go to step 6.
  5. Output: Display “Big Number”.
  6. Output: Display “Small Number”.
  7. End: End the flowchart.


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: 

  1. Start: Begin the flowchart.
  2. Input: Ask the user “How many letters are in the English alphabet?”
  3. Process: Store the user’s input in a variable.
  4. Decision: Check if the input is equal to 26.
    • If Yes, go to step 5.
    • If No, go to step 6.
  5. Output: Display “Correct”.
  6. Output: Display “Incorrect”.
  7. End: End the flowchart.


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: 

  1. Start: Begin the flowchart.
  2. Input: Ask the user to enter the first number.
  3. Input: Ask the user to enter the second number.
  4. Decision: Check if the first number is greater than the second number.
    • If Yes, go to step 5.
    • If No, go to step 6.
  5. Process: Calculate the sum of the two numbers.
  6. Process: Calculate the difference between the two numbers (first number - second number).
  7. Output: Display the result (either the sum or the difference).
  8. End: End the flowchart.


Challenge Yourself

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:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Final Project

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

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 dataexpected outcomeactual outcomepass/fail
1

width = 8.5
length = 11

perimeter: 39

2

width = 4.9
length 9.2

perimeter: 28.2

3

width = 3.4
length 6.1

perimeter: 19

Ans: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

Test numberTest dataExpected outcomeActual outcomePass/Fail
1width = 8.5, length = 11perimeter: 39perimeter: 39Pass
2width = 4.9, length = 9.2perimeter: 28.2perimeter: 28.2Pass
3width = 3.4, length = 6.1perimeter: 19perimeter: 19Pass


Q6. Average of three numbers:

- This shows the Scratch solution to calculate the average of three numbers:

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

- Create this program in Python to perform the same task.

Ans: Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

The document Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6 is a part of the Class 6 Course IGCSE Cambridge Computing for Year 6.
All you need of Class 6 at this link: Class 6
28 videos|17 docs|5 tests

Top Courses for Class 6

FAQs on Textbook Solutions: Block it out: Moving from blocks to text - IGCSE Cambridge Computing for Year 6 - Class 6

1. What are the differences between Scratch and Python programming languages?
Ans. Scratch is a visual programming language designed for beginners, with blocks of code that can be dragged and dropped to create programs. Python, on the other hand, is a text-based programming language that offers more flexibility and complexity in coding.
2. How can Python IDLE be used in Script mode for programming?
Ans. Python IDLE can be used in Script mode by writing code directly into the editor, saving the file with a .py extension, and running the program by clicking on the 'Run' button or using the 'F5' key.
3. What are some common data types in Python, and how can they be manipulated?
Ans. Common data types in Python include strings, integers, and real numbers. These data types can be manipulated by performing operations such as concatenation for strings, arithmetic calculations for integers, and mathematical operations for real numbers.
4. How does Python handle error detection and correction in programming?
Ans. Python uses try-except blocks to handle errors in programming. The try block contains the code that may cause an error, while the except block catches and handles the error, preventing the program from crashing.
5. How can flowcharts and algorithms be used in Python programming to improve code efficiency?
Ans. Flowcharts and algorithms can be used to plan and visualize the structure of a program before coding in Python. By breaking down the problem into steps and designing algorithms, programmers can create more efficient and organized code.
28 videos|17 docs|5 tests
Download as PDF
Explore Courses for Class 6 exam

Top Courses for Class 6

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

practice quizzes

,

Important questions

,

Previous Year Questions with Solutions

,

shortcuts and tricks

,

past year papers

,

pdf

,

Exam

,

Summary

,

video lectures

,

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

,

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

,

Semester Notes

,

mock tests for examination

,

Viva Questions

,

Objective type Questions

,

MCQs

,

Extra Questions

,

study material

,

Textbook Solutions: Block it out: Moving from blocks to text | IGCSE Cambridge Computing for Year 6 - Class 6

,

ppt

,

Free

,

Sample Paper

;