Page 424 - ComputerScience_Class_11
P. 424
Program 1: To demonstrate a program to check whether a number is even or odd.
Program 1.py
File Edit Format Run Options Window Help
# using if, else and return keywords
def check_number(num): # Function definition
if num % 2 == 0: # if keyword
return "Even" # return keyword
else: # else keyword
return "Odd" # return keyword
# Taking input from user
number = int(input("Enter a number: "))
# Calling the function
result = check_number(number)
# Displaying result
print("The number is", result)
Output
Enter a number: 5
The number is Odd
12.9.2 Identifiers
An identifier is the name given to a variable, function, class, object or any other element in a Python program. It is
used to identify and refer to these elements so that they can be accessed and used throughout the program. In simple
terms, identifiers are user-defined names that help programmers store data and perform operations.
For example, in the statement marks = 90, the word marks is an identifier because it is the name of the variable
that stores the value 90. In Python, specific rules must be followed when naming identifiers. These rules are given
below:
Rules for Identifiers in Python
Here are some rules for identifiers in Python:
• Identifiers can contain letters (A–Z, a–z), digits (0–9) and underscore (_).
• An identifier must begin with a letter or an underscore (_).
• An identifier cannot start with a digit.
• Special symbols like @, #, $, %, etc., or space are not allowed.
• An identifier cannot be a keyword (such as if, else, for, while).
• Identifiers are case-sensitive (name, Name and NAME are different).
For example,
• Valid: total, _count, marks1
• Invalid: 1sum (starts with digit)
for (keyword)
total-marks (special symbol)
422 Touchpad Computer Science (Ver. 3.0)-XI

