Practical – 149 : Write and test a python program to perform data and data type operations, string operations, date, input and output, output formatting and operators
# Program to demonstrate data types, strings, dates, input/output, formatting, and operators
# Importing the datetime module for date handling
import datetime
# —————————–
# 1. Input and Output
# —————————–
name = input(“Enter your name: “)
age = int(input(“Enter your age: “))
print(“\n— Basic Information —“)
print(“Name:”, name)
print(“Age:”, age)
# —————————–
# 2. Data Types and Operations
# —————————–
# Integer
a = 10
# Float
b = 3.5
# Boolean
is_adult = age >= 18
# String
city = “Mumbai”
# Display types
print(“\n— Data Type Check —“)
print(“Type of a:”, type(a))
print(“Type of b:”, type(b))
print(“Type of is_adult:”, type(is_adult))
print(“Type of city:”, type(city))
# —————————–
# 3. String Operations
# —————————–
print(“\n— String Operations —“)
full_info = name + ” from ” + city
print(“Full Info:”, full_info)
print(“Upper Case:”, full_info.upper())
print(“Lower Case:”, full_info.lower())
print(“Length of string:”, len(full_info))
# —————————–
# 4. Date Handling
# —————————–
print(“\n— Date and Time —“)
today = datetime.datetime.now()
print(“Current Date & Time:”, today)
print(“Formatted Date:”, today.strftime(“%d-%m-%Y”))
print(“Year:”, today.year)
print(“Month:”, today.month)
print(“Day:”, today.day)
# —————————–
# 5. Output Formatting
# —————————–
print(“\n— Output Formatting —“)
print(f”Hello {name}, you are {age} years old and live in {city}.”)
print(“Value of a: {}, Value of b: {}”.format(a, b))
# —————————–
# 6. Operators
# —————————–
print(“\n— Arithmetic Operators —“)
print(“Addition (a + b):”, a + b)
print(“Subtraction (a – b):”, a – b)
print(“Multiplication (a * b):”, a * b)
print(“Division (a / b):”, a / b)
print(“\n— Comparison Operators —“)
print(“Is a > b?”, a > b)
print(“Is age >= 18?”, is_adult)
print(“\n— Logical Operators —“)
print(“Is adult and lives in Mumbai?”, is_adult and city == “Mumbai”)
print(“Is adult or lives in Delhi?”, is_adult or city == “Delhi”)
OUTPUT :
Enter your name: Saiyam
Enter your age: 20
— Basic Information —
Name: Saiyam
Age: 20
— Data Type Check —
Type of a: <class ‘int’>
Type of b: <class ‘float’>
Type of is_adult: <class ‘bool’>
Type of city: <class ‘str’>
— String Operations —
Full Info: Saiyam from Mumbai
Upper Case: SAIYAM FROM MUMBAI
Lower Case: saiyam from mumbai
Length of string: 18
— Date and Time —
Current Date & Time: 2025-06-06 15:20:35.123456
Formatted Date: 06-06-2025
Year: 2025
Month: 6
Day: 6
— Output Formatting —
Hello Saiyam, you are 20 years old and live in Mumbai.
Value of a: 10, Value of b: 3.5
— Arithmetic Operators —
Addition (a + b): 13.5
Subtraction (a – b): 6.5
Multiplication (a * b): 35.0
Division (a / b): 2.857142857142857
— Comparison Operators —
Is a > b? True
Is age >= 18? True
— Logical Operators —
Is adult and lives in Mumbai? True
Is adult or lives in Delhi? True