MASTERMIND ENGLISH MEDIUM SCHOOL
SUBJECT: COMPUTER
SCIENCE
CLASS-VIII(CAMBRIDGE)
PYTHON PROGRAMMING
PRACTICAL
Lab-2-(HY) – (Variable declaration, variable types)
Question:
Write a python program to take various inputs from user (roll, age, mark,
section, name, present_input) and print the data types of the inputs.
In the last line if the student is present then welcome the student with name,
section and mark.
Answer:
Python code:
# Taking inputs from the user using various data
types # Printing values and their types
roll= int(input("Enter roll: ")) # int
print (type (roll))
age = int(input("Enter age: ")) # int
print (type (age))
mark = float(input("Enter mark: ")) # float
print (type (mark))
section = input("Enter section (one character): ") # single
character string
print (type (section))
present_input = input("Is the student present? (true/false): ")
name=input("Enter name: ") # string
print (type (name))
# Convert string input to boolean
present = True if present_input == "true" else False
# Conditional output
if present:
print(f"Welcome,{name} from section {section}.Your MARK is
{mark}.")
else:
print(f"{name} is absent today.")
Output:
Enter roll: 8
<class 'int'>
Enter age: 15
<class 'int'>
Enter mark: 97.5
<class 'float'>
Enter section (one character): A
<class 'str'>
Is the student present? (true/false): true
Enter name: Nabila Shams
<class 'str'>
Welcome, Nabila Shams from section \A.Your MARK is 97.5.