MALAD KANDIVALI EDUCATION SOCIETY’S
NAGINDAS KHANDWALA COLLEGE OF COMMERCE,
ARTS & MANAGEMENT STUDIES & SHANTABEN NAGINDAS
KHANDWALA COLLEGE OF SCIENCE
MALAD [W], MUMBAI – 64
(EMPOWERED AUTONOMOUS)
(Reaccredited ‘A’ Grade by NAAC)
(AFFILIATED TO UNIVERSITY OF MUMBAI)
(ISO 9001:2015)
CERTIFICATE
Name: Karan Gusain
Roll No: 12 Programme: Python Programming Semester: III
This is certified to be a bonafide record of practical works done by the above student in the
college laboratory for the course Python Programming(Course Code: UML301PP24MA) for the
partial fulfilment of Semester III of [Link]. CS(AIML) during the academic year 2025-2026.
The journal work is the original study work that has been duly approved in the year 2025-2026
by the undersigned.
External Examiner (Subject-In-Charge)
Prof. Anusha P.P
SUBJECT: Python Programming
CLASS: SY BSC CS(AIML)
SEMESTER: III
ROLL NO: 12
Sr No. Topic Date Sign
1. Data Types: Crete a Student Grade Tracker system using python
that uses various data types such as strings, integers, floats,
Booleans, lists, and dictionaries to implement these functionalities.
2. Write a program that prompts the user to enter a number, and
then prints "Positive" if the number is greater than zero,
"Negative" if the number is less than zero, and "Zero" if the
number is equal to zero.
3. Write a program that prompts the user to enter a password. If the
password is "password123", the program should print "Access
granted". Otherwise, the program should print "Access denied".
4. Write a program that prompts the user to enter a number, and
then prints the factorial of that number using Recursion.
5. a) Write a program that prints the first 10 numbers of the
Fibonacci sequence using a for loop.
b) Write a program that prompts the user to enter a string, and
then prints each character of the string on a separate line using a
for loop.
c) Write a program that prints the first 10 even numbers using a
while loop.
6. Write a program that prompts the user to enter two numbers, and
then prints the larger number using a conditional expression.
7. File Handling Objective Tasks:
a) Create a new text file and write some text to it.
b) Open the file in read mode and display its contents.
c) Open the file in append mode and add some more text to it.
d) Open the file in write mode and overwrite its contents with new
text.
8. Reading and Writing Text Files Objective:
a) Read a text file line by line and display each line.
b) Write text to a new text file line by line.
c) Append text to an existing text file.
d) Use the 'with' statement to open a file and read its contents.
e) Use the 'with' statement to open a file and write text to it.
9. Write a program to draw a triangle, rectangle, and square using
the turtle module.
10. Write a program to print the star pattern using a nested for loop:
11 Build a password generator program taking all the aspects into
consideration.
12 Write a Python program to create a calculator by using a separate
module
Practical 1:
Data Types: Crete a Student Grade Tracker system using python that uses various data types
such as strings, integers, floats, Booleans, lists, and dictionaries to implement these
functionalities.
Code:
student_list = [] # list
# Adding student details
def add_student():
name = input("\nEnter your name: ")
roll_no = int(input("Enter your roll no: "))
subjects = ['Physics','Chemistry','Maths']
marks = {} # Dictionary to store marks
for sub in subjects:
mark = float(input(f"Enter your marks for {sub}: "))
marks[sub] = mark # Adding marks with the subject into the marks
dictionary
# Calculate average
avg = (sum([Link]()))/len(subjects)
passed = avg >= 35 # boolean
# Store all data into the dictionary
student_data ={
'name': name,
'roll no': roll_no,
'Marks': marks,
'Average': avg,
'Passed': passed
}
# Append the data into the student list
student_list.append(student_data)
# Display student details
def display_student():
if not student_list:
print("No student record available")
return
for student in student_list:
print("\n---Student Report---")
print(f"name: {student['name']}")
print(f"roll no: {student['roll no']}")
print("Marks ~")
for sub, mrks in student['Marks'].items():
print(f"{sub}: {mrks}")
print(f"Average is {student['Average']:.2f}")
print(f"Result: {'Passed' if student['Passed'] else 'Failed'} ")
# Main Function
def main():
while True:
print("--- Student Grade Tracker ---")
print("\n1. Add Student")
print("\[Link] Student")
print("\[Link]")
choice = int(input("\nEnter your choice: "))
if choice == 1:
add_student()
elif choice == 2:
display_student()
elif choice == 3:
print("Thankyou for using Student Grade tracker !")
break
else:
print("Invalid choice. Please try again!")
# Run the main function
main()
Output :
Practical 2:
Write a program that prompts the user to enter a number, and then prints "Positive" if the number
is greater than zero, "Negative" if the number is less than zero, and "Zero" if the number is equal
to zero.
Code :
while True:
num = int(input("Enter the number: "))
if num > 0:
print(f"{num} is positive")
elif num < 0:
print(f"{num} is negative")
else :
print("Number is zero! ")
choice = input("Do you want to try another number? (Yes/No)").lower()
if choice == 'n' or choice == 'no':
print("Thank you!")
break
Output :
Practical 3:
Write a program that prompts the user to enter a password. If the password is "password123", the
program should print "Access granted". Otherwise, the program should print "Access denied".
Code :
Correct_pass = "password123"
user_pass = input("Enter the password: ")
if Correct_pass == user_pass:
print("Access granted")
else:
print("Access denied")
Output :
Practical 4:
Write a program that prompts the user to enter a number, and then prints the factorial of that
number using Recursion.
Code :
def fact(n):
if n == 0 or n ==1:
return 1
else:
return n* fact(n-1)
n = int(input("Enter the number : "))
if n<0:
print("Factorial is not defined for negative number!")
else:
print(f"Factorial of {n} is {fact(n)}")
Output :
Practical 5:
a) Write a program that prints the first 10 numbers of the Fibonacci sequence using a for loop.
Code :
def fib(n):
if n<=1:
return n
else:
return fib(n-1)+ fib(n-2)
steps = int(input("Enter the number of terms: "))
for i in range(steps):
print(f"{fib(i)} \t",end = "")
Output :
b) Write a program that prompts the user to enter a string, and then prints each character of the
string on a separate line using a for loop.
Code :
str = input("Enter the string: ")
for i in str :
print(f"{i}")
Output :
c) Write a program that prints the first 10 even numbers using a while loop.
Code :
i =0
while (i<20):
if i %2 == 0:
print(f"{i}\t",end='')
i=i+1
Output :
Practical 6:
Write a program that prompts the user to enter two numbers, and then prints the larger number
using a conditional expression.
Code :
num_1 = int(input("enter the first number: "))
num_2= int(input("enter the second number: "))
if num_1 > num_2:
print(f"{num_1} is greater than {num_2}")
else:
print(f"{num_2} is greater than {num_1}")
Output :
Practical 7:
File Handling Objective Tasks:
a) Create a new text file and write some text to it.
Code :
with open("[Link]", "w") as file:
[Link]("This is Python Programming.\n")
[Link]("I love Programming.\n")
print("Step (a): File created and text written.\n")
Output :
b) Open the file in read mode and display its contents.
Code :
with open("[Link]", "r") as f:
content = [Link]()
print("Step (b): File contents are:\n")
print(content)
Output :
c) Open the file in append mode and add some more text to it.
Code :
with open("[Link]", "a") as f:
[Link]("This is an appended line.\n")
print("\nStep (c): Additional text appended.\n")
Output :
d) Open the file in write mode and overwrite its contents with new text.
Code :
with open("[Link]", "w") as f:
[Link]("The file has been overwritten with new content.\n")
print("Step (d): File contents overwritten.\n")
Output :
Practical 8:
Reading and Writing Text Files Objective:
a) Read a text file line by line and display each line.
Code :
print("Step (a): Reading file line by line:")
with open("[Link]", "r") as f:
for line in f:
print([Link]())
Output :
b) Write text to a new text file line by line.
Code :
lines = ["First line of text\n","Second line of text\n", "Third line
of text\n"]
with open("[Link]", "w") as f:
[Link](lines)
print("Step (b): Text written line by line to new file.\n")
Output :
c) Append text to an existing text file.
Code :
with open("[Link]", "a") as f:
[Link]("This is an appended line.\n")
print("Step (c): Text appended to the file.\n")
Output :
d) Use the 'with' statement to open a file and read its contents.
Code :
with open("[Link]", "r") as f:
content = [Link]()
print(content)
Output:
e) Use the 'with' statement to open a file and write text to it.
Code :
with open("[Link]", "w") as f:
[Link]("This file was created using the 'with' statement.\n")
[Link]("It contains some sample text.\n")
print("Step (e): New file created and text written using 'with'.")
Output :
Practical 9:
Write a program to draw a triangle, rectangle, and square using the turtle module.
Code :
import turtle
# Screen setup
screen = [Link]()
[Link]('blue')
[Link](width= 800, height= 600)
# Creating main turtle
t = [Link]()
[Link]('turtle')
[Link](3)
[Link](1)
# Square
[Link]('red')
[Link]()
[Link](-200,100)
[Link]()
[Link]('red')
t.begin_fill()
for _ in range (4):
[Link](100)
[Link](90)
t.end_fill()
# Rectangle
[Link]('yellow')
[Link]()
[Link](0,0)
[Link]()
[Link]('yellow')
t.begin_fill()
for _ in range(2):
[Link](100)
[Link](90)
[Link](50)
[Link](90)
t.end_fill()
# Triangle
[Link]('grey')
[Link]()
[Link](200,0)
[Link]()
[Link]('grey')
t.begin_fill()
for _ in range(3):
[Link](100)
[Link](120)
t.end_fill()
# Final Text
[Link]()
[Link](-200,-200)
[Link]()
[Link]('black')
[Link]("Turtle Graphics!",font=('Algerian',18,'bold'))
[Link]()
Output :
Practical 10:
Write a program to print the star pattern using a nested for loop.
# Pattern 1
Code :
n = int(input("Enter the number: "))
for i in range(1, n+1):
print("*"*(i), end="")
print("")
Output :
#Pattern 2
Code:
n = int(input("Enter the number: "))
for i in range(1, n + 1):
print(' ' * (n - i) + '*' * i)
Output:
#Pattern 3
Code:
n = int(input("Enter the number: "))
for i in range(n, 0, -1):
print("*"*(i), end="")
print("")
Output:
#Pattern 4
Code:
n = int(input("Enter the number: "))
for i in range(1, n+1):
print(" "* (n-i), end="")
print("*"*(2*i-1), end="")
print("")
Output:
Practical 11:
Build a password generator program taking all the aspects into consideration.
Code :
import random
import string
def generate_password( length = 12, use_uppercase = True,
use_lowercase = True, use_digits = True, use_special_chars =
True, avoid_ambigous = True):
# Define character sets based on user choices
characters = ''
if use_uppercase:
characters += string.ascii_uppercase
if use_lowercase:
characters += string.ascii_lowercase
if use_digits:
characters += [Link]
if use_special_chars:
characters += [Link]
if avoid_ambigous:
ambiguos_chars = '1iloO0'
characters = ''.join(filter(lambda char: char not in
ambiguos_chars, characters))
# check if there are characters to choose from
if not characters:
return 'Password cannot be generated with the selected
options'
# Generate a random password
password = ''.join([Link](characters) for _ in
range(length))
return password
if __name__ == "__main__":
print("Password Generator")
print("------------------")
# Prompt the user for password generation options
length = int(input("Enter the desired passowrd length: "))
use_uppercase = input("Include uppercase letters (Y/N)?
").strip().lower() == 'y'
use_lowercase = input("Include lowercase letterrs (Y/N)?
").strip().lower() == 'y'
use_digits = input("Include Digits (Y/N)?
").strip().lower() == 'y'
use_special_chars = input("Include special characters
(Y/N)? ").strip().lower() == 'y'
avoid_ambigous = input("Avoid ambigous characters (Y/N)?
").strip().lower() == 'y'
# Generate a password with the specified options
password =
generate_password(length,use_uppercase,use_lowercase,use_digits
,use_special_chars,avoid_ambigous)
# Print the generated password
print("\nGenerated Password: ",password)
Output :
Practical 12:
Write a Python program to create a calculator by using a separate module.
Code :
Creating a file named ‘[Link]’ in the same directory as of the main program
# Calculator functions
def add(a,b):
return f"The Sum is: {a+b}"
def sub(a,b):
return f"The Difference is: {a-b}"
def mul(a,b):
return f"The Multiplication is : {a*b}"
def div(a,b):
return f"The Division is : {a/b}"
def modulo(a,b):
return f"The Modulo is : {a%b}"
Importing the file ‘[Link]’ in the main program
import modulee as md
while True:
num_1 = int(input("\nEnter the first number: "))
num_2 = int(input("Enter the second number: "))
print("**** Calculator ****")
print("\[Link]")
print("\[Link]")
print("\[Link]")
print("\[Link]")
print("\[Link]")
choice = int(input("Enter your choice: "))
match (choice):
case 1:
add = [Link](num_1,num_2)
print(add)
case 2:
sub = [Link](num_1,num_2)
print(sub)
case 3:
mul = [Link](num_1,num_2)
print(mul)
case 4:
div = [Link](num_1,num_2)
print(div)
case 5:
mod = [Link](num_1,num_2)
print(mod)
cont = input("Do you want to continue?
(yes(y)/no(n))").lower()
if cont == 'no' or cont == 'n':
break
print("\nThankyou!")
Output :