0% found this document useful (0 votes)
0 views

python multiple basic codes

This document certifies that Mr. Saurabh Manohar Sawant is a bona fide student of Karmaveer Bhaurao Patil Institute of Management Studies and Research, completing his Python lab assignments for the BCA program in the academic year 2024-2025. It includes an index of various programming assignments related to Python, covering topics such as basic arithmetic operations, list manipulations, date and time handling, file input/output, and GUI programming. The assignments demonstrate practical applications of Python programming concepts learned during the course.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

python multiple basic codes

This document certifies that Mr. Saurabh Manohar Sawant is a bona fide student of Karmaveer Bhaurao Patil Institute of Management Studies and Research, completing his Python lab assignments for the BCA program in the academic year 2024-2025. It includes an index of various programming assignments related to Python, covering topics such as basic arithmetic operations, list manipulations, date and time handling, file input/output, and GUI programming. The assignments demonstrate practical applications of Python programming concepts learned during the course.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Rayat Shikshan Sanstha's

KARMAVEER BHAURAO PATIL INSTITUTE OF MANAGEMENT


STUDIES AND RESEARCH, VARYE SATARA

CERTIFICATE

This is to certify that Mr. saurabh manohar sawant is bonafide student of


KBPIMSR, Satara studying in BCA-III (Semester-VI). He/She has successfully completed
his/her Lab assignments for Python(Lab Course XI based on CC601) in Academic year
2024-2025.

Place: Satara

Date:

Miss.R.N.Gaikwad Dr.R.D.Kumbhar
Teacher in charge Head of Department

Examiner Dr.B.S.Sawant
(Director)
INDEX
Sr. Page.
Particular Date Sign
No No
1 Program to display name and address. 16/1/25 1
Program to Accept two number and display
2 addition, subtraction, multiplication,division 17/1/25 2
and modules.

3 Program to calculate factorial of given number. 23/1/25 3


Program to create a list of 100 numbers and
4 separate those numbers in two different list 30/1/25 4
one includes odd number other even.
Program to display maximum number and
5 minimum number from given list
31/1/25 5-6

6 Program to demonstrate slicing. 01/02/25 7


Program to demonstrate set operators (union ,
7 intersection, minus)
06/02/25 8

8 Program to print current date and time. 07/02/25 9

9 Program to Today’s Year, Month, and Date 13/02/25 10

10 Program to convert Date to String 14/02/25 11


Program to display the Calendar of a given
11 month. 20/02/25 12

12 Program to display calendar of the given year. 21/02/25 13

13 Program to demonstrate File input. 06/03/25 14

14 Program to demonstrate File output. 24/03/25 15

15 Program two add two numbers using GUI. 25/03/25 16-17


Assignment 1
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.1: Program to display name and address.
#Method 1:
def display():
name = input("Enter your name: ")
address = input("Enter your address: ")
print("Name: ",name,"\n","Address: ",address)
display()

#Method 2:
def display():
name = input("Plz Enter Your Name Sir/Madam: ")
address = input("Plz Enter Your Address Sir/Madam: ")
age = int(input("Plz Enter Your Age Sir/Madam: "))
print("Name: ",name,"\n","Address: ",address,"\n","Age: ",age)
display()

Output:
Assignment 2
Name: saurabh manohar sawant
Class: BCA III (SEM-VI) Roll.No: 189

Q.2: Program to accept two numbers and display addition, subtraction, multiplication,
division and modules.

#Method 1:
def add():
a = 10
b = 20
c=a+b
return c
sum = add()
print("Addition= ",sum)"""
#Method 2:
def add():
a = 10
b = 20
return a + b
sum = add()
print("Addition= ",sum)"""
#Method 3:
def add(a,b):
return a + b
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))
sum = add(num1,num2)
print("Addition= ",sum)"""
#Method 4:
def calculations(a,b):
return a + b,a - b,a * b,a / b,a % b,a // b
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))
add,sub,mul,div,remain,floor = calculations(num1,num2)
print("\n","Addition= ",add,"\n","Subtraction= ",sub,"\n","Multiplication=
",mul,"\n","Division= ",div,"\n","Modulus= ",remain,"\n","Floor= ",floor)

Output:
Assignment 3
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.3: Program to calculate factorial of given number.

#Using loop
num = int(input("Enter a number: "))
fact = 1
if num < 0:
print("Factorial of number is not possible")
elif num == 0:
print("Factorial of 0 is 1")
else:
for i in range(1,num + 1):
fact = fact * i
print("Factorial of",num,"is",fact)

#Using function
def fact(n):
if n == 1:
return 1
else:
return n*fact(n-1)

num = int(input("Enter a number: "))


print("The factorial of ",num,"is",fact(num))

Output:
Assignment 4
Name: saurabh manohar sawant
Class: BCA III (SEM-VI) Roll.No: 189

Q.4: Program to create a list of 100 numbers and separate those numbers in two
different list one includes odd number other even.

#using for loop


number = list(range(1, 101))
odd = []
even = []

for num in number:


if num % 2 == 0:
even.append(num)
else:
odd.append(num)

print("Odd numbers:", odd)


print("Even numbers:", even)

#using lambda function


number=list(range(1,101))
even_num=list(filter(lambda num:num%2==0,number))
odd_num=list(filter(lambda num:num%2!=0,number))

print("Even Numbers :" ,even_num)


print("Odd Numbers :" ,odd_num)

Output:
Assignment 5
Name: saurabh manohar sawant
Class: BCA III (SEM-VI) Roll.No:189

Q.5: Program to display maximum number and minimum number from given list.

#Maximum Number
#using loop
number = [99, 67, 44, 54, 27, 9]
max_num=number[0]
for num in number:
if num>max_num:
max_num=num
print("Maximun num: ",max_num)

#using function
def max_num(lst):
maximum=lst[0]
for num in lst:
if num>maximum:
maximum=num
return maximum
number=[99, 67, 44, 54, 27, 9]
res=max_num(number)
print(f"Maximum number: {res}")

#using built-in max()


number=[99, 67, 44, 54, 27, 9]
print(max(number))

#using reduce
from functools import reduce
number=[99, 67, 44, 54, 27, 9]
max_num=reduce(lambda a,b:a if a>b else b, number)
print(max_num)

#using sort method


number=[1, 22, 99, 67, 44, 54, 27, 9]
number.sort(reverse=True)
print("Maximum number: ",number[0])

Output:
#Minimum Number
#using loop
number = [2, 99, 67, 44, 54, 27, 9]
min_num=number[0]
for num in number:
if num<min_num:
min_num=num
print("Minimum num: ",min_num)

#using function
def min_num(lst):
minimum=lst[0]
for num in lst:
if num<minimum:
minimum=num
return minimum
number=[2, 99, 67, 44, 54, 27, 9]
res=min_num(number)
print(f"Minimum number: {res}")

#using built-in max()


number=[2, 99, 67, 44, 54, 27, 9]
print(min(number))

#using reduce
from functools import reduce
number=[2, 99, 67, 44, 54, 27, 9]
min_num=reduce(lambda a,b:a if a<b else b, number)
print(min_num)

#using sort method


number=[ 22, 99, 67, 44, 54, 27, 9]
number.sort(reverse=False)
print("Minimum number: ",number[0])
Ouput:
Assignment 6
Name: saurabh manohar
Roll.No: 189
sawant Class: BCA III
(SEM-VI)
Q.6: Program to demonstrate slicing.

numbers=[5,8,1,30,59,62,44,81,74,66,89]

print(numbers[::])
print(numbers[:7])
print(numbers[2:])
print(numbers[0:10:2])
print(numbers[::-1])
print(numbers[-8:-1])
print(numbers[9:1:-1])
print(numbers[-1:-8:-1])

Ouput:
Assignment 7
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.7: Program to demonstrate set operators (union , intersection, minus)

setA = {1,2,3,4}
setB = {3,4,5,6}

print(setA | setB)
print(setA.union(setB))
print(setA & setB)
print(setA.intersection(setB))
print(setA - setB)
print(setA.difference(setB))
Ouput:
Assignment 8
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.8: Program to print current date and time.
from datetime import datetime

current=datetime.now()

current_date=current.date()
current_time=current.time()

print(current)
print("Current Date: ",current_date)
print("Current Time: ",current_time)

Output:
Assignment 9
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.9: Program to Today’s Year, Month, and Date.

from datetime import datetime

current=datetime.now()

current_year=current.year
current_month=current.month
current_day=current.day

print(current)
print("Current year: ",current_year)
print("Current month: ",current_month)
print("Current day: ",current_day)
Output:
Assignment 10
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.10: Program to convert Date to String.

import datetime

current_datetime=datetime.datetime.now()
print("current date and time:",current_datetime)

str_date = current_datetime.strftime("%d-%m-%Y")

print("current date and time:",str_date)


print(type(str_date))
print("The Current day is: ",current_datetime.strftime("%d"))
print("The Current week is: ",current_datetime.strftime("%W"))
print("The Current month is: ",current_datetime.strftime("%B"))
print(" TheCurrent year is: ",current_datetime.strftime("%Y"))
print("Current Hour in a 24-hour clock format: ",current_datetime.strftime("%H"))
print("AM OR PM : ",current_datetime.strftime("%p"))

Output:
Assignment 11
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.11: Program to display the Calendar of a given month.
import calendar
# Enter the month and year
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))

# display the calendar


print(calendar.month(yy,mm))

Output:
Assignment 12
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.12: Program to display calendar of the given year.

import calendar

year = int(input("Enter Year: "))

print("\n" + calendar.calendar(year))

Output:
Assignment 13
Name: saurabh manohar sawant
Class: BCA III (SEM-VI) Roll.No: 189

Q.13: Program to demonstrate file Input.

import fileinput
for line in fileinput.input(files ='rohan.txt'):

print(line)

Output:
Assignment 14
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.14: Program to demonstrate File output.

try:
fileName = "rohan.txt";
fileObj = open(fileName,'r');
readText = fileObj.read();

except FileNotFoundError:
print("Failed to open file: ",fileName, "No such file");
else:
print("File is opened successfully",fileObj);

Output:
Assignment 15
Name: saurabh manohar
sawant Class: BCA III Roll.No: 189
(SEM-VI)
Q.15: Program two add two numbers using GUI.

import tkinter

def addNums():
try:
first = int(firstWin.get())
second = int(secoWin.get())
answer = first + second
txtBx.delete("1.0", "end") # Clear previous result
txtBx.insert("1.0", str(answer)) # Insert the new result
except ValueError:
txtBx.delete("1.0", "end")
txtBx.insert("1.0", "Error") # Show an error message for invalid input

bob = tkinter.Tk()
bob.title('Adding Box')

# Widgets for input and labels


firstWin = tkinter.Entry(bob)
firstLbl = tkinter.Label(bob, text='Enter first number')
secoWin = tkinter.Entry(bob)
secoLbl = tkinter.Label(bob, text='Enter second number')

# Add button and text box


addButton = tkinter.Button(bob, text='Add', command=addNums)
txtBx = tkinter.Text(bob, height=1, width=10)

# Organize widgets
firstLbl.pack()
firstWin.pack()
secoLbl.pack()
secoWin.pack()
addButton.pack()
txtBx.pack()

bob.mainloop()
Output:

You might also like