2025
AICT Assignment:
From: M. Usman
To: Miss Maham
Roll:2025-AI-552
Example 1: Hello World
print("Hello, World!")
Example 2: Printing Multiple Lines
print("Welcome to Python Programming")
print("University of Engineering and Technology")
print("CSC100L Lab")
Example 3: Printing with Blank Lines
print("First Line")
print()
print("Third Line")
Example 4: Using Comments
# This is a comment - Python ignores this line
print("This will be printed")
# Comment after code
# Comments help explain your code
# You can write multiple comment lines
print("Hello")
Roll:2025-AI-552
Example 5: Creating Simple Variables
name = "Ahmed"
age = 20
city = "Lahore"
print(name)
print(age)
print(city)
Example 6: Printing Variables with Messages
name = "Ali"
age = 21
print("Student name is", name)
print("Age is", age)
Example 7: Using f-strings (Formatted Strings)
name = "Hassan"
Roll:2025-AI-552
age = 22
cgpa = 3.75
print(f"My name is {name}")
print(f"I am {age} years old")
print(f"My CGPA is {cgpa}")
Example 8: Variable Names Demo
# Correct variable names
student_name = "Ahmed Khan"
student1 = "Ali Hassan"
_student = "Usman"
print(student_name)
print(student1)
print(_student)
Example 9: Working with Integers
age = 21
marks = 85
year = 2024
print("Age:", age)
print("Marks:", marks)
Roll:2025-AI-552
print("Year:", year)
print("Type of age:", type(age))
Example 10: Integer Arithmetic
a = 15
b=5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
Example 11: Working with Floats
height = 5.8
cgpa = 3.75
price = 99.99
print("Height:", height)
print("CGPA:", cgpa)
print("Price:", price)
Roll:2025-AI-552
print("Type of cgpa:", type(cgpa))
Example 12: Float Arithmetic
x = 10.5
y = 2.5
print("Addition:", x + y)
print("Subtraction:", x - y)
print("Multiplication:", x * y)
print("Division:", x / y)
Example 13: Creating Strings
name = "Ahmed Khan"
university = "UET Lahore"
message = 'Hello, World!'
print(name)
print(university)
print(message)
print("Type of name:", type(name))
Roll:2025-AI-552
Example 14: String Operations
first_name = "Ahmed"
last_name = "Khan"
# Combining strings
full_name = first_name + " " + last_name
print("Full name:", full_name)
# String length
print("Length:", len(full_name))
# Repeating strings
print("=" * 20)
Example 15: String Methods
text = "python programming"
print("Original:", text)
Roll:2025-AI-552
print("Uppercase:", [Link]())
print("Title Case:", [Link]())
print("Capitalized:", [Link]())
Example 16: Using Booleans
is_student = True
has_passed = False
is_enrolled = True
print("Is student:", is_student)
print("Has passed:", has_passed)
print("Type:", type(is_student))
Example 17: Comparisons
x = 10
y=5
print("x > y:", x > y)
print("x < y:", x < y)
print("x == y:", x == y)
print("x != y:", x != y)
Roll:2025-AI-552
Example 18: String to Integer
age_text = "25"
print("Before conversion:", age_text, type(age_text))
age_number = int(age_text)
print("After conversion:", age_number, type(age_number))
result = age_number + 5 print("Age + 5 =", result)
Example 19: String to Float
cgpa_text = "3.75"
cgpa_number = float(cgpa_text)
print("CGPA:", cgpa_number)
print("Type:", type(cgpa_number))
Roll:2025-AI-552
Example 20: Number to String
age = 21
age_text = str(age)
message = "I am " + age_text + " years old"
print(message)
Example 21: Float to Integer
price = 99.99
price_int = int(price)
print("Original price:", price)
print("Price as integer:", price_int)
Example 22: Take input
value= input("Enter a number")
print("The entered number is:",value)
Roll:2025-AI-552
Example 23:Change data type of a variable
value= input("Enter a number")
print("The entered number is:",value)
print("Data type of the entered value is:",type(value))
value=float(value)
print("data type of the entered value is:",type(value))
Example 24: Special characters
print("hello \n world")
print("hello \t world")
print("hello \\ world")
Roll:2025-AI-552
Example 25: Conditional structures
if(15>10):
print("15 is greater than 10")
else:
print("10 is greater than 15")
Example 26: elif statement
if(15>10):
print("15 is greater than 10")
elif(10==15):
print("10 is equal to 15")
else:
print("10 is less than 15")
Example 27: While loop
a=1
while(a<4):
print("Hello World")
a+=1
Roll:2025-AI-552
Example 28: For loop
a=1
for a in range(3):
print("Hello, World!")
Example 29:For in string
for a in "yohohoho":
print(a, end="-")
Example 30: Functions
Roll:2025-AI-552
def sum(a,b):
return a+b
a=1
b=2
print("Sum is:",sum(a,b))
Example 31: Default Parameters
def sum(a=1,b=2):
return a+b
print("Sum is:",sum(2,3))
print("Sum is:",sum())
Example 32: Built-in functions
a=1
b=2
print("max:",max(a,b))
print("min:",min(a,b))
print("pow:",pow(a,b))
Roll:2025-AI-552
Example 33: String manipulation
string="hello world"
print(string[1])
print(string[-1])
print(string[4])
Example 34: String Slicing
string="hello world"
print(string[1:5])
Example 35: List
Roll:2025-AI-552
li={1,2,3,45,6,7,8}
print(li)
Example 36: string list
li=["uno","duo","tres","quatro"]
print(li)
Example 37: List indices and Elements
li=[1,"duo",2.5,True]
print(li[0],type(li[0]))
print(li[1],type(li[1]))
print(li[2],type(li[2]))
Example 38: List() method
li=["uno","duo","tres","quatro"]
li2=list(li)
[Link]()
print(li2)
Roll:2025-AI-552
Example 39: del ()
li=["uno","duo","tres","quatro"]
del li[2]
print("Updated List:",li)
Example 40: Append and Insert and Remove
li=[1,2,3,4,5,6,7,8,9,10]
print("Original List:",li)
[Link](11)
[Link](4)
[Link](0,0)
print("Updated List:",li)
Roll:2025-AI-552
Task 1: Personal Information Display
Write a program that stores and displays your personal information.
name="Usman"
rn="2025-AI-552"
Dep="Artificial Intelligence"
sem="1st Semester"
age=17
print("================================")
print(" STUDENT INFORMATION ")
print("================================")
print("Name: ",name)
print("Registeration Number: ",rn)
print("Department: ",Dep)
print("Semester: ",sem)
print("Age: ",age)
print("================================")
Roll:2025-AI-552
Task 2: Simple Calculator
Write a program that performs basic arithmetic operations on two numbers.
num1=25
num2=8
sum=num1+num2
sub=num1-num2
mul=num1*num2
div=num1/num2
print("Number 1: ",num1)
print("Number 2: ",num2)
print("================================")
print("Addition: ",sum)
print("Subtraction: ",sub)
print("Multiplication: ",mul)
Roll:2025-AI-552
print("Division: ",div)
Task 3: Rectangle Area and Perimeter
Write a program that calculates the area and perimeter of a rectangle.
length=12.5
width=8.0
cal_area=length*width
cal_prmtr=2*(length+width)
print("Rectangle Calculations")
print("----------------------")
print("Length: ",length)
print("Width: ",width)
print("Area: ",f"{cal_area:.2f}")
print("Perimeter: ",f"{cal_prmtr:.2f}")
Roll:2025-AI-552
Task 4: String Manipulation
Given the string: text = "university of engineering and technology lahore"
text = "university of engineering and technology lahore"
u_text = [Link]()
title_text = [Link]()
length = len(text)
word=[Link]()[2]
print("Original: ", text)
print("Uppercase: ", u_text)
print("Title Case: ", title_text)
print("Length: ", length)
print("Word: ", word)
Roll:2025-AI-552
Task 5: Grade Calculator
Write a program that calculates total marks and percentage.
math=85
physics=78
coding=92
total_marks=math+physics+coding
percentage=(total_marks/300)*100
print("===== GRADE REPORT =====")
print("Math: ",math)
print("Physics: ",physics)
print("Programming: ",coding)
print("------------------------")
print("Total Marks: ",total_marks,"/ 300")
print("Percentage: ",f"{percentage:.2f}%")
print("========================")
Roll:2025-AI-552
Task 6: Temperature Converter
Write a program that converts temperature from Celsius to Fahrenheit.
temp_cel=25
temp_fahr=(temp_cel*9/5)+32
print("Temperature Conversion")
print("----------------------")
print(f"Celsius: {temp_cel}°C")
print("Fahrenheit: ",f"{temp_fahr:.1f}°F")
Roll:2025-AI-552
Task 7: Student Data Card
Write a program that displays a complete student data card.
name="Muhammad Usman"
rn="2025-AI-552"
Dep="Artificial Intelligence"
age=17
cgpa=3.75
city="Kamoke"
enrolled=True
print("╔════════════════════════════════╗")
print("║ STUDENT DETAILS ║")
print("╚════════════════════════════════╝")
print("Name : ",name)
print("Reg no : ",rn)
print("Department : ",Dep)
print("Age : ",age)
print("CGPA : ",cgpa)
print("City : ",city)
print("Enrolled : ",enrolled)
Roll:2025-AI-552
Task 8: Type Conversion Practice
Write a program demonstrating type conversions.
age_str="21"
marks_str="85.5"
count=100
print("Original Values:")
print(f"age_str = \"{age_str}\" (type: {type(age_str)})")
print(f"marks_str = \"{marks_str}\" (type: {type(marks_str)})")
print(f"count = {count} (type: {type(count)})")
age_str=int(age_str)+4
marks_str=float(marks_str)*1.1
Roll:2025-AI-552
count="Total : "+str(count)
print("\nAfter type Conversion:")
print(f"age_str to int: {age_str} (type: {type(age_str)})")
print(f"marks_str to float: {marks_str:.2f} (type: {type(marks_str)})")
print(f"count to str: \"{count}\" (type: {type(count)})")
Task 9: Boolean Logic
Write a program that uses boolean variables and comparisons
has_laptop=True
has_internet=True
age=18
cgpa=3.2
print("Student Status Check")
print("--------------------")
print("Has_laptop:",has_laptop)
Roll:2025-AI-552
print("Has_internet:",has_internet)
print("age>=18:",age>=18)
print("cgpa>2.5:",float(cgpa)>2.5)
Task 10: Text Formatter
Write a program that formats text in different ways.
course_name="application of information and communication technologies"
upper=course_name.upper()
title=course_name.title()
capital=course_name.capitalize()
length=len(course_name)
Words=course_name.split()
words=len(Words)
print("╔══════════════════════════════════════════
════════╗")
print("║ APPLICATION OF INFORMATION AND COMMUNICATION ║")
print("║ TECHNOLOGIES ║")
print("╚══════════════════════════════════════════
════════╝")
print("Title Case: ",title)
Roll:2025-AI-552
print("Capitalized: ",capital)
print("Length: ",length)
print("Words: ",words)
Task 11: Check equality of two lists
li=[1,2,3]
li2=[1,2,4]
print(li==li2)
Task 12:Built-in functions
Roll:2025-AI-552
li=[1,2,3,4,5,6,7,8,9,10]
li2=[9,9,0,6,3,6,8,]
print("Original List:",li)
print([Link](5))
[Link]()
print("Sorted List:",li2)
[Link]()
print("Reversed List:",li)
Task 13: Passing lists as parameters
def add(li):
sum=0
for i in li:
sum+=i
return sum
li=[1,2,34,5,6]
print("Sum is:",add(li))
Roll:2025-AI-552
Task 14: Import Libraries
import math
print("Value of pi:",[Link])
Task 15: Even number between 1 to 20
li=list(range(2,20,2))
print("Even numbers between 1 and 20:",li)
Task 16: Ask the user to enter a string( str) and a character(c ) and find how
many times the character(c ) appears in the string?
li=input("Enter elements separated by space:").split()
a=input("Enter character")
print([Link](a))
Roll:2025-AI-552
Task 17: Write a function that will return all the vowels in a string
def vowels(str):
vowels="aeiouAEIOU"
count=0
for i in str:
if i in vowels:
count+=1
print("Number of vowels:",count)
str="Hello World"
vowels(str)
Task 18: Write a program that inputs salary. If salary is greater than or equal to
30000, then deducts 7% of salary. If salary is 20000 or more but less than 30000,
then deduct 5% of salary. If salary is less than 20000 then deduct nothing. Print
the net salary
(sal)=input("What is your salary?")
sal=float(sal)
if (sal)>=30000:
net=sal-(sal*0.7)
elif (sal)>=20000:
net=sal-(sal*0.5)
else:
Roll:2025-AI-552
net=sal
print("Net salary is:",int(net))
Roll:2025-AI-552