Page 241 - CTS - CSA TP - Volume 2
P. 241
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 122 : Write and test a python program to
demonstrate print statement, comments,
and different types of variables
Objectives
At the end of this exercise you shall be able to
• develop python program to demonstrate print statement, comments, and different types of variables.
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• Latest Version of Python
Procedure
TASK 1: String Variables
Code:
# Example 1: String Variables with Comment
name = “John”
print(“My name is”, name)
Explanation:
• name = “John”: This line declares a variable named name and assigns the string value “John” to it. In
Python, you can create a string by enclosing characters in single or double quotes.
• print(“My name is”, name): The print statement is used to display output. In this case, it prints the string “My
name is” followed by the value stored in the name variable. Multiple values can be printed in a single print
statement, and they are separated by commas.
Output:
TASK 2: Numeric Variables
Code:
# Example 2: Variables and Data Types
# Declare variables with different data types
name = “John” # String
age = 25 # Integer
height = 5.9 # Float
is_student = True # Boolean
226