Chapter 3
computational thinking
Programming languages
Slides by
Ms Abeera Sikandar
lecturer
bahria college anchorage
computer sciences
• Program Requirement: • Algorithm:(Set of steps)
1. Input numbers from 1. Input number1
user 2. Input number2
2. Select operation (+,-,*,/) 3. Result = number1 +number2
3. Output the result of 4. Output result
operation.
Interface: - interface is how the user interacts with the program.
Interface: - interface is how the user interacts with the program.
Scratch has colorful block-based interface
Python has text-based interface
Python Interface
Scratch Interface: - interface is how the user interacts with the program.
1. Create variables
2. Starting event
3. Make the program
Scratch Interface: - interface is how the user interacts with the program.
1. Create variables
Two types of variables are present in scratch:
• Answer variable in sensing block
• My variable in variables block
Scratch Interface: - interface is how the user interacts with the program.
2. Starting event
To will make program start.
3 event blocks are:start program, event on block
Purpose of event block: to start the program working
Scratch Interface: - interface is how the user interacts with the program.
3. Make the program
Scratch VS Python
Scratch Python
Block based programming language Text based programming language
For input, ask block is used For input ‘input’ keyword is used
For output, looks block is used For output, ‘print’ keyword is used
Example Program:
Algorithm: Scratch code:
Set secretpassword to diamond7
Input user name
Output Hello
Output user name
Output secretpassword.
Example Program:
Algorithm: Python code:
Set secretpassword to diamond7
Input user name
Output Hello
Output user name
Output secretpassword.
Naming variables in Python:
Names of variables should be done wisely and meaningful.
Rules for naming variables are:
1. Be one word only - no spaces. For example: secretpassword
2. Use only letters, numbers, and underscore For example: secret_password7
3. Start with a letter. For example: secretpassword
Setting value in variable in Python:
While setting value in a variable, a format is followed: Note:
Inverted commas will only
variablename = “value” come when value is
1. Forexample alphabets/text
secretpassword = “diamond7” Like
Name = “Ali”
Age = 12
Program errors (mistakes) in Python:
While typing python command, following mistakes can occur:
1. Spell a word incorrectly.
2. Push words in wrong order.
3. Use capital letter instead of lower-case letter.
4. Leave out brackets or other symbols
Program errors (mistakes) in Python:
Example for finding errors:
While typing python command, following mistakes can occur:
1. Spell a word incorrectly.
2. Push words in wrong order.
3. Use capital letter instead of lower-case letter.
4. Leave out brackets or other symbols
Program errors (mistakes) in Python:
Example for finding errors:
While typing python command, following mistakes can occur:
1. Spell a word incorrectly.
2. Push words in wrong order.
3. Use capital letter instead of lower-case letter.
4. Leave out brackets or other symbols
1. City = “Paris”
2. print(age)
3. age = input(“How old are you? “)
4. Error messages help us to find the error and then type the command again without error.
Saving python command as program
Saving commands in python can help to reuse the same program. We don’t need to
rewrite the whole program.
How to save?
1. Create a file 2. Enter commands 3. Save the file 4. Run the program
Colours in python
The commands in python have different colours
Names of variables Black
input and output commands purple
Text strings green
Colours in python and Error finding
The commands in python have different colours
Correct Incorrect
Error messages
The commands in python have different colours
Incorrect Error message
IDE
Integrated Development Environment
IDE is software we use to write and run program.
Properties of an IDE
For example: 1. It lets you to enter & save commands.
For scratch, software is Scratch 2. It displays error messages.
3. It runs the program.
4. It lets user enter input and shows
For python, software is Python Shell IDLE output.
IDE
Integrated Development Environment
Scratch IDE Python Shell IDLE
1. Colourful block-based programming
1. Simple text-based programming
language.
language.
2. Its IDE is web based.
2. Make and save program.
3. Area to make program.
3. Output is shown in python shell.
4. Stage area for output of program