0% found this document useful (0 votes)
9 views21 pages

PYTHON (1) Set 1 Prasad

The document outlines various programming assignments related to Python programming and Full Stack Development with Django and Flask. It includes practical exercises such as temperature conversion, area calculation, password generation, and the creation of RESTful APIs. Each practical is accompanied by a program aim, code, and expected output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views21 pages

PYTHON (1) Set 1 Prasad

The document outlines various programming assignments related to Python programming and Full Stack Development with Django and Flask. It includes practical exercises such as temperature conversion, area calculation, password generation, and the creation of RESTful APIs. Each practical is accompanied by a program aim, code, and expected output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Faculty of Engineering & Technology

Python programming & Full Stack


Development with Django &
flask Laboratory(303105258)

INDEX
PAGE DATE OF DATE OF
S. PROGRAM NO PERFORMANCE SUBMISSION SIGNATURE MARKS
NAME
NO

1 Set 1
1. A program
that converts
temperatures
from Fahrenheit
to Celsius and
vice versa.

2. A program
that calculates
the area and
perimeter of a
rectangle.

3. A program
that generates a
random
password of a
specified
length.

4. A program
that calculates
the average of a
list of numbers.

5. A program
that checks if a
given year is a
leap year.

6. A program
that calculates
the factorial of
a number.

7. A program
that checks if

Enrollment Number:2303031460115 Page No: 2


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

a given string is
a palindrome.

8. A program
that sorts a list
of numbers in
ascending or
descending
order.

9. A program
that generates a
multiplication
table for a given
number.

10. A program
that converts a
given number
from one base
to another.

2 Set 2
1. A program
that models a
bank account,
with classes for
the account, the
customer, and
the bank.

2. A program
that simulates a
school
management
system, with
classes for the
students, the
teachers, and
the courses.

Enrollment Number:2303031460115 Page No: 3


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

Enrollment Number:2303031460115 Page No: 4


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

4 . A program that creates a


web application that
implements user
authentication and
authorization.
5. A program that creates a
web application that
integrates with third-party
APIs to provide additional
functionality.
5 Set 5
1. A program that creates a
simple RESTful API that
returns a list of users in
JSON format.
2. A program that creates a
RESTful API that allows
users to create, read,
update, and delete
resources.
3. A program that creates a
RESTful API that
authenticates users using a
JSON Web Token.
4. A program that creates a
RESTful API that paginates
the results of a query to
improve performance.
5. A program that creates a
RESTful API that supports
data validation and error
handling.

Enrollment Number:2303031460115 Page No: 5


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

SET-01

PRACTIACAL 01
AIM: A program that converts temperatures from Fahrenheit to Celsius and vice
versa.
Program:
celsius=int(input("enter the temperature in celsius: \n"))
fahrenheit=int(input("enter the temperature in fahrenheit: \n"))
celsius_result=(fahrenheit-32)*5/9
print(f"{fahrenheit}F is equal to {celsius_result}C")
fahrenheit_result=(celsius*9/5)+32
print(f"{celsius}C is equal to {fahrenheit_result}F")
Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 6


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 02
AIM: A program that calculates the area and perimeter of a rectangle.
Program:
length=int(input("Enter the length of rectangle: \n"))
breadth=int(input("Enter the breadth of rectangle: \n"))
Area=(length*breadth)
print("Area of rectangle:",Area)
Perimeter=2*(length+breadth)
print("Perimeter of rectangle:",Perimeter)

Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 7


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 03
AIM: A program that generates a random password of a specified length.
Program:
import random
import string
password_length=12
characters = string.ascii_letters+string.digits +string.punctuation
password=''.join(random.choice(characters) for i in range(password_length))
print(f"Your generated password is:{password}")

Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 8


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 04
AIM: A program that calculates the average of a list of numbers.
Program:
num=[1,2,3,4,5,6]
sum=0
for i in num:
sum=sum+i
average=sum/len(num)
print(f"The average of numbers is {average}")
Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 9


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 05
AIM: A program that checks if a given year is a leap year.
Program:
year=int(input("Enter a year: \n"))
if (year%4==0 and year%100!=0)or (year%400==0):
print("leap year")
else:
print("Not a leap year")

Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 10


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 06
AIM: A program that calculates the factorial of a number.
Program:
def factorial(n):
if n==0 or n==1:
return 1
else:
return n*factorial(n-1)
num=int(input("Enter the number: \n"))
result=factorial(num)
print(f"The factorial of a {num} is: {result}")

Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 11


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTIACAL 07
AIM: A program that checks if a given string is a palindrome.
Program:
#using method
def is_palindrome (s):
s=''.join(s.split()).lower()
return s==s[::-1]
input_string=input("Enter a string: \n")
if is_palindrome(input_string):
print(f"{input_string} is a palindrome.")
else:
print(f"{input_string}is not a palindrome.")
#Using for loop
input_string=input_string.lower()
rev=""
for i in range(len(input_string)-1,-1,-1):
rev+=input_string[i]
if input_string==rev:
print(f"{input_string} is a palindrome.")
else:
print(f"{input_string}is not a palindrome.")
#or
input_string=input_string.lower()
rev=""
for i in input_string:

Enrollment Number:2303031460115 Page No: 12


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

rev=i+rev
if input_string==rev:
print(f"{input_string} is a palindrome.")
else:
print(f"{input_string} is not a palindrome.")
Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 13


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 08
AIM: A program that sorts a list of numbers in ascending or descending order.
Program:
numlist=[3,2,5,1,6]
ascending_sorted=sorted(numlist)
descending_sorted=sorted(numlist,reverse=True)
print("Original list:",numlist)
print("ascending list:",ascending_sorted)
print("descending list:",descending_sorted)
Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 14


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 09
AIM: A program that generates a multiplication table for a given number.
Program:
num=int(input("Enter the number: \n"))
for i in range(1,11,1):
result=(num*i)
print(f"{num}*{i}={result}")
Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 15


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

PRACTICAL 10
AIM: A program that converts a given number from one base to another.
Program:
def to_base10(number,base):
return int(number,base)
def from_base10(number,base):
digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if number==0:
return "0"
result=""
while number>0:
result=digits[number%base]+result
number=number//base
return result
number=input("Enter the number: \n")
source_base=int(input("Enter the source base: \n"))
target_base=int(input("Enter the target base: \n"))
base10_number=to_base10(number,source_base)
converted_number=from_base10(base10_number,target_base)
print(f"{number} in base {converted_number} in base {target_base}.")

Enrollment Number:2303031460115 Page No: 16


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

Output:

AMBATI SAI HUSSAINI

Enrollment Number:2303031460115 Page No: 17


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

SET-02
PRACTICAL 1
AIM: A program that models a bank account, with classes for the account, the
customer, and the bank.
Program:
class Account:
def init (self, account_number, balance=0.0):
self.account_number = account_number
self.balance = balance

def deposit(self, amount):


self.balance += amount
print(f"Deposited {amount}. New balance is {self.balance}.")

def withdraw(self, amount):


if amount > self.balance:
print("Insufficient funds")
else:
self.balance -= amount
print(f"Withdrew {amount}. New balance is {self.balance}.")

def get_balance(self):

Enrollment Number:2303031460115 Page No: 18


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

return self.balance

class Customer:
def init (self, name, customer_id):
self.name = name
self.customer_id = customer_id
self.accounts = []

def add_account(self, account):


self.accounts.append(account)

def get_accounts(self):
return self.accounts

def str (self):


return f"Customer [Name: {self.name}, ID: {self.customer_id}]"

class Bank:
def init (self, name):
self.name = name
self.customers = []

def add_customer(self, customer):


self.customers.append(customer)

def get_customer_by_id(self, customer_id):

Enrollment Number:2303031460115 Page No: 19


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

for customer in self.customers:


if customer.customer_id == customer_id:
return customer
return None

def str (self):


return f"Bank [Name: {self.name}]"

bank = Bank("National Bank")

customer1 = Customer("Ram", 1)
customer2 = Customer("Sita", 2)

bank.add_customer(customer1)
bank.add_customer(customer2)

account1 = Account("ACC1001", 500)


account2 = Account("ACC1002", 1000)

customer1.add_account(account1)
customer2.add_account(account2)

account1.deposit(200)
account1.withdraw(100)
print(f"Balance for {customer1.name}: {account1.get_balance()}")

Enrollment Number:2303031460115 Page No: 20


Faculty of Engineering & Technology
Python programming & Full Stack
Development with Django &
flask Laboratory(303105258)

account2.deposit(500)
account2.withdraw(300)
print(f"Balance for {customer2.name}: {account2.get_balance()}")

print(customer1)
print(customer2)
print(bank)

Output:

Enrollment Number:2303031460115 Page No: 21

You might also like