Currently set to Index
Currently set to Follow
Skip main navigation

Comparison Between the Scratch and Python Code

Learn more about the Scratch and Python code.
In this step, I am going to look at a fairly simple game using string operations, and compare the Scratch and Python code. You will create the game too!
This is a game that asks the players to provide various words, such as nouns, verbs, and adjectives. These words are then entered into a story that has missing nouns, verbs, and adjectives — often with humorous results.
Two children reading a book with images of a dragon blowing fire onto a castle, a sun, and rainbow, all coming out of the book.
I’ll begin by writing a simple story, and will then look for words to replace. This is a slightly edited section from the Simple English Wikipedia entry on ice cream:
Ice cream is a frozen dessert made from cream, with added flavours and sweeteners. This mixture is quickly frozen while it is stirred, so that large ice crystals do not form. Some ice cream is made with carrageenan, extracted from seaweed, so that it is not sticky. There are many different flavours of ice cream, such as chocolate and vanilla. Ice cream often has things added to it for flavour, like chocolate chips, nuts, or fruit.
You can use this passage for your game, or come up with your own version. Now that I have the basic text, I can replace some of the words, such as nouns and verbs. I will ask the user to add new nouns and verbs which be entered in the respective places below:
Ice cream is a frozen dessert made from plural noun , with added flavours and sweeteners. This mixture is quickly frozen while it is verb ending in ed , so that large plural noun do not form. Some ice cream is made with noun , extracted from seaweed, so that it is not sticky. There are many different flavours of ice cream, such as food and food . Ice cream often has things added to it for flavour, like noun, noun , or noun.
Now I want you to think about how you could start to create the game. The solution is fairly simple:
  1. Ask for the user to input some words, such as plural nouns, verbs, and foods
  2. Assign these inputs to variables
  3. Insert these variable values into the strings to complete the paragraph
You are going to look at the three programming constructs used in the game in Scratch and Python, to compare how these are implemented in both a block-based and a text-based programming language.
    1. Asking for input from the user and assigning variables to that inputTwo Scratch blocks: ask 'Give me a plural noun' and wait set noun_1 to answer
      noun_1 = input('Give me a plural noun')
      
       
 
    1. Outputting strings 
      Two Scratch blocks:<br>say 'Ice cream is a frozen dessert'<br>say noun_1
       
      print('Ice cream is a frozen dessert')
      print (noun_1)
      
       
 
    1. Concatenating strings 
      A noun 1 variable in a join block alongside 'with added flavours'. This is within another join block alongside 'ice cream is'. This outer join block is in a say block
       
      print("Ice cream is..." + noun_1 + ", with added flavours...")
      
       
 
 
To make the game, you can begin by asking the user for lots of words, and finish by inserting them into some strings that will be printed.
 
Here is the code for a partially completed Python program for the game.
 
noun_1 = input("Give me a plural noun ")
verb = input("Give me a verb ending in ed ")
noun_2 = input("Give me another plural noun ")
noun_3 = input("Give me a noun ")
adjective = input("Give me an adjective ")
### Add more code here to complete the game

print("Ice cream is a frozen dessert made from " + noun_1 + ", with added flavours and sweeteners")
print("This mixture is quickly frozen while it is " + verb + ", so that large " + noun_2 + " do not form.")
print("Some ice cream is made with " + noun_3 + " extracted from seaweed, so that it is not " + adjective)
### Add more code here to complete the game
 

Challenge

 
 
    1. Create a new Python program
 
    1. Copy in the code from above
 
    1. Add the following variables and complete the game: 
        • food_1
       
        • food_2
       
        • noun_4
       
        • noun_5
       
        • noun_6
       
       
 
 
In the comments section share:
 
 
    • Your code
 
    • Any requests for help that you have
 
    • What you found most challenging about this task
 
 
Remember to use three tilde characters (~~~) at the start and end of your code, as in this example comment text:
 
I created this program.

~~~
print("This is my code")
~~~
Refer to our ‘Sharing code on FutureLearn’ guide for more information.
This article is from the free online

Scratch to Python: Moving from Block- to Text-based Programming

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education