2.
My First Program
Programming the computer
Python provides functions that allow users to provide input to the
2. My first program
computer and view the output on the screen. The most common
way of providing input to the computer is via the keyboard.
Python is a text-based programming language. It requires you to
type syntaxes of codes for developing programs and applications.
To access the online editor, scan the QR code or access the link
below:
https://python.qubitscs.com
Click on the
“Text” tab to open
the text editor
Page|8
Programming the computer
Python has a function called print() which is used to display the
2. My First Program
output.
Syntax
Function
name Argument
print ("Hello world")
Open parenthesis Close parenthesis
For example, if you want to write a program to show "My first
program":
1. Open the python editor.
2. Type : print("My first program")
3. Scroll down and click on the "Run" button to execute the
program.
• You can use multiple print statements in a program.
• Each print statement displays on the next line by default.
• You can use single or double quotes to display text.
Page | 9
Example:
Programming the computer
Write a program to show the following output:
2. My first program
The program:
print("Welcome")
print("to")
print ("Grade 6 class")
Exercise:
Write a program to show the following output:
The program:
Example :
Write a program to show the following shape:
The program:
print("*")
print("**")
print("***")
print("****")
print("*****")
P a g e | 10
Programming the computer
Challenge:
With the help of print() command display the following pattern:
2. My First Program
The program:
Python has a function called input() that allows the user to
provide input from the keyboard. It prompts the user to insert
value, data or information required for processing.
Syntax
Function
name Prompt
x=input ("Enter your name")
Variable name Open parenthesis Close parenthesis
Page | 11
Example :
Programming the computer
Write a program to ask your name and print it.
Let us try it together:
2. My first program
name=input("What is your name ")
print(name)
If you look at the result you will see that the program stopped and
is waiting for you to give your input (here it is your name).
Write your name and click "Enter".
P a g e | 12
Programming the computer
2. My First Program
Prints the word "name"
print("name") because the word is inside
the parentheses.
print(name) Prints the value of name, for
example the name you
entered in the program.
Exercise:
Write a program to ask the name and age of a person using
input() function and show the answer using print() function.
The program:
Page | 13