ASSIGNMENT -PYTHON
SARA K JOBY S4 CSE DELTA U2403238 ROLLNO:35
Colab link :
[Link]
Sl2AIgFD?usp=sharing
1) PROGRAM
name=input("enter consumer name")
ID=int(input("enter consumer ID"))
units=int(input("enter units"))
print("consumer details")
print("name: ",name)
print("ID: ",ID)
print("units consumed: ",units)
while True:
print("menu options")
print("[Link] total amount (before tax)")
print("[Link] tax amount")
print("[Link] total amount (after tax)")
print("[Link] final electricity bill")
print("[Link]")
choice=int(input("enter option"))
if units<= 100:
amount=units * 2
elif units<= 200:
amount=(100 * 2)+((units - 100) * 3)
else:
amount=(100*2)+(100 * 3) +((units-200)*5)
amount=amount+150
tax=(amount*10)/100
net=amount+tax
if choice==1:
print("total amount before tax: ",amount)
elif choice==2:
print(" tax: ",tax)
elif choice==3:
print("total amount after tax: ",net)
elif choice==4:
print("final electricity bill")
print("=======================")
print("=======================")
print("consumer details")
print("----------------")
print("consumer details")
print("name: ",name)
print("ID: ",ID)
print("units consumed: ",units)
print("==================")
print("total amount before tax: ",amount)
print("tax amount: ",tax)
print("total amount after tax: ",net)
print("=============================")
print("Net Payable Amount: ",net)
print("=============================")
print("Thank you dear customer")
elif choice==5:
print("exit")
break
else:
print("invalid option! try again.")
OUTPUT
enter consumer namesara
enter consumer ID1234
enter units150
consumer details
name: sara
ID: 1234
units consumed: 150
menu options
[Link] total amount (before tax)
[Link] tax amount
[Link] total amount (after tax)
[Link] final electricity bill
[Link]
enter option1
total amount before tax: 500
menu options
[Link] total amount (before tax)
[Link] tax amount
[Link] total amount (after tax)
[Link] final electricity bill
[Link]
enter option2
tax: 50.0
menu options
[Link] total amount (before tax)
[Link] tax amount
[Link] total amount (after tax)
[Link] final electricity bill
[Link]
enter option3
total amount after tax: 550.0
menu options
[Link] total amount (before tax)
[Link] tax amount
[Link] total amount (after tax)
[Link] final electricity bill
[Link]
enter option4
final electricity bill
=======================
=======================
consumer details
----------------
consumer details
name: sara
ID: 1234
units consumed: 150
==================
total amount before tax: 500
tax amount: 50.0
total amount after tax: 550.0
=============================
Net Payable Amount: 550.0
=============================
Thank you dear customer
menu options
[Link] total amount (before tax)
[Link] tax amount
[Link] total amount (after tax)
[Link] final electricity bill
[Link]
enter option5
Exit
2)PROGRAM
string=input("enter string: ")
while True:
print("=========================")
print("menu options")
print("[Link] length of string")
print("[Link] string to uppercase,lowercase and title case")
print("[Link] occurrence of character or substring")
print("[Link] position of word or charactter")
print("[Link] a word or character with another")
print("[Link] whether string contains only alphabets , digits or
alphanumeric")
print("[Link] leading and trailing space")
print("[Link] string into words and join using separator")
print("[Link] whether string start or end with given word")
print("[Link] the string and check whether it is a palindrome")
print("[Link] and decode the string")
print("[Link]")
print(" ")
print(" ")
choice=int(input("enter option: "))
if choice==1:
print("length of string: ",len(string))
elif choice==2:
print("string converted into uppercase:",[Link]())
print("string converted into lowercase:",[Link]())
print("string converted into title case:",[Link]())
elif choice==3:
char=input("enter character or substring: ")
print("count of character or substring: ",[Link](char))
elif choice==4:
char=input("enter character or substring: ")
print("position of character or substring",[Link](char))
elif choice==5:
char=input("enter character or word to replace with")
new=input("enter new character or word")
print("string after replacing: ",[Link](char,new))
elif choice==6:
if [Link]():
print("string contains only digits ")
elif [Link]():
print("string contains only alphabets")
elif [Link]():
print("string contains only alphanumeric")
else:
print("string contains digits,numbers,special characters")
elif choice==7:
print("removed leading and trailing space: ",[Link]())
elif choice==8:
words=[Link]()
print("words in string: ",words)
separator=input("enter separator: ")
print("joined string: ",[Link](words))
elif choice==9:
word=input("enter word to check: ")
if [Link](word):
print("string starts with given word")
if([Link](word)):
print("string ends with given word")
elif choice==10:
reverse=string[::-1]
print("reverse of string: ",reverse)
if string==reverse:
print("is palindrome")
else:
print("not palindrome")
elif choice==11:
encode=[Link]("utf-8")
print("encoded string: ",encode)
decode=[Link]("utf-8")
print("decoded string: ",decode)
elif choice==12:
print("exit program")
break
else:
print("invalid option.. try again")
OUTPUT
enter string: hello 123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 1
length of string: 9
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 2
string converted into uppercase: HELLO 123
string converted into lowercase: hello 123
string converted into title case: Hello 123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 3
enter character or substring: l
count of character or substring: 2
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 4
enter character or substring: e
position of character or substring 1
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 5
enter character or word to replace withhello
enter new character or wordworld
string after replacing: world 123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 6
string contains digits,numbers,special characters
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 7
removed leading and trailing space: hello 123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 8
words in string: ['hello', '123']
enter separator: 9
joined string: hello9123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 9
enter word to check: 123
string ends with given word
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 10
reverse of string: 321 olleh
not palindrome
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 11
encoded string: b'hello 123'
decoded string: hello 123
=========================
menu options
[Link] length of string
[Link] string to uppercase,lowercase and title case
[Link] occurrence of character or substring
[Link] position of word or charactter
[Link] a word or character with another
[Link] whether string contains only alphabets , digits or alphanumeric
[Link] leading and trailing space
[Link] string into words and join using separator
[Link] whether string start or end with given word
[Link] the string and check whether it is a palindrome
[Link] and decode the string
[Link]
enter option: 12
exit program
3)PROGRAM
cart=[]
print("enter 10 products")
for i in range(10):
product=input("enter product name: ")
[Link](product)
while True:
print("=============")
print("menu")
print("[Link] current products")
print("[Link] new product")
print("[Link] new product")
print("[Link] product by name")
print("[Link] product by index")
print("[Link] occurrence of specific product")
print("[Link] product and display index")
print("[Link] product list in ascending order")
print("[Link] order")
print("[Link] all products from cart")
print("[Link]")
print(" ")
print(" ")
choice=int(input("enter option: "))
if choice==1:
print("current products ",cart)
elif choice==2:
product=input("enter new product ")
[Link](product)
print("product added :",cart)
elif choice==3:
product=input("enter new product ")
index=int(input("enter index "))
[Link](index,product)
print("product inserted: ",cart)
elif choice==4:
product=input("enter product to remove: ")
if product in cart:
[Link](product)
print("product removed: ",cart)
elif choice==5:
index= int(input("enter index to remove: "))
[Link](index)
print("Product removed: ",cart)
elif choice == 6:
product= input("Enter product name to count: ")
count = [Link](product)
print("product count in cart: ",count)
elif choice==7:
product=input("Enter product name to search: ")
if product in cart:
print("Product found at index:", [Link](product))
else:
print("product not found")
elif choice==8:
[Link]()
print("product list sorted in ascending order: ",cart)
elif choice==9:
[Link]()
print("product list reversed: ",cart)
elif choice==10:
[Link]()
print("all products cleared: ",cart)
elif choice==11:
print("exit")
break
else:
print("invalid option! try again")
OUTPUT
enter 10 products
enter product name: grapes
enter product name: banana
enter product name: orange
enter product name: kiwi
enter product name: avacado
enter product name: cherry
enter product name: papaya
enter product name: apple
enter product name: apple
enter product name: mango
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 1
current products ['grapes', 'banana', 'orange', 'kiwi', 'avacado',
'cherry', 'papaya', 'apple', 'apple', 'mango']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 2
enter new product lemon
product added : ['grapes', 'banana', 'orange', 'kiwi', 'avacado',
'cherry', 'papaya', 'apple', 'apple', 'mango', 'lemon']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 3
enter new product plum
enter index 2
product inserted: ['grapes', 'banana', 'plum', 'orange', 'kiwi',
'avacado', 'cherry', 'papaya', 'apple', 'apple', 'mango', 'lemon']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 4
enter product to remove: cherry
product removed: ['grapes', 'banana', 'plum', 'orange', 'kiwi',
'avacado', 'papaya', 'apple', 'apple', 'mango', 'lemon']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 5
enter index to remove: 1
Product removed: ['grapes', 'plum', 'orange', 'kiwi', 'avacado',
'papaya', 'apple', 'apple', 'mango', 'lemon']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 6
Enter product name to count: apple
product count in cart: 2
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 7
Enter product name to search: grapes
Product found at index: 0
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 8
product list sorted in ascending order: ['apple', 'apple', 'avacado',
'grapes', 'kiwi', 'lemon', 'mango', 'orange', 'papaya', 'plum']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 9
product list reversed: ['plum', 'papaya', 'orange', 'mango', 'lemon',
'kiwi', 'grapes', 'avacado', 'apple', 'apple']
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 10
all products cleared: []
=============
menu
[Link] current products
[Link] new product
[Link] new product
[Link] product by name
[Link] product by index
[Link] occurrence of specific product
[Link] product and display index
[Link] product list in ascending order
[Link] order
[Link] all products from cart
[Link]
enter option: 11
Exit
4)PROGRAM
courses = {}
print("Enter details for 5 courses:")
for i in range(5):
code=input("enter Course Code: ")
title=input("enter Course Title: ")
faculty=input("enter Faculty Name: ")
credits=input("enter Credit Details: ")
courses[code] = {"Title": title,"Faculty": faculty,"Credits": credits}
while True:
print("==============")
print("menu")
print("[Link] a new course record")
print("[Link] all course records")
print("[Link] existing course details")
print("[Link] a course using course code")
print("[Link] for a course")
print("[Link] if course code exists")
print("[Link] all course codes")
print("[Link] all course details")
print("[Link] dictionary")
print("[Link] all records")
print("[Link]")
print(" ")
print(" ")
choice = int(input("enter your choice: "))
if choice==1:
code=input("enter course code: ")
title=input("enter Course title: ")
faculty=input("enter faculty name: ")
credits=input("enter credit details: ")
courses[code] = {"Title": title,"Faculty": faculty,"Credits":
credits}
print("course added ")
elif choice == 2:
if courses:
for code, details in [Link]():
print(f"\nCourse Code: {code}")
for key, value in [Link]():
print(f"{key}: {value}")
else:
print("No course records found.")
elif choice == 3:
code = input("enter course code to update: ")
if code in courses:
title=input("enter new course title: ")
faculty=input("enter new faculty name: ")
credits=input("enter new credit details: ")
courses[code]={"Title": title,"Faculty": faculty,"Credits":
credits}
print("Course updated .")
else:
print("course not found.")
elif choice==4:
code=input("enter course code to delete: ")
if code in courses:
del courses[code]
print("course deleted .")
else:
print("Course not found.")
elif choice==5:
code=input("enter course code to search: ")
if code in courses:
print("course details:")
for key, value in courses[code].items():
print(f"{key}: {value}")
else:
print("course not found.")
elif choice==6:
code=input("enter course code to check: ")
if code in courses:
print("course code exists.")
else:
print("course code does not exist.")
elif choice==7:
print("course codes:", list([Link]()))
elif choice==8:
print("course details:", list([Link]()))
elif choice==9:
newcourses = [Link]()
print("dictionary copied .")
print("copied dictionary:", newcourses)
elif choice==10:
[Link]()
print("all course records cleared.")
elif choice==11:
print("exiting program")
break
else:
print("invalid choice! Try again.")
OUTPUT
Enter details for 5 courses:
enter Course Code: 100
enter Course Title: maths
enter Faculty Name: sara
enter Credit Details: 10
enter Course Code: 200
enter Course Title: java
enter Faculty Name: anna
enter Credit Details: 20
enter Course Code: 300
enter Course Title: python
enter Faculty Name: issac
enter Credit Details: 30
enter Course Code: 400
enter Course Title: c program
enter Faculty Name: alice
enter Credit Details: 40
enter Course Code: 500
enter Course Title: biology
enter Faculty Name: joby
enter Credit Details: 50
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 1
enter course code: 600
enter Course title: chemistry
enter faculty name: bob
enter credit details: 60
course added
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 2
Course Code: 100
Title: maths
Faculty: sara
Credits: 10
Course Code: 200
Title: java
Faculty: anna
Credits: 20
Course Code: 300
Title: python
Faculty: issac
Credits: 30
Course Code: 400
Title: c program
Faculty: alice
Credits: 40
Course Code: 500
Title: biology
Faculty: joby
Credits: 50
Course Code: 600
Title: chemistry
Faculty: bob
Credits: 60
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 3
enter course code to update: 600
enter new course title: physics
enter new faculty name: stella
enter new credit details: 70
Course updated .
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 4
enter course code to delete: 600
course deleted .
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 5
enter course code to search: 100
course details:
Title: maths
Faculty: sara
Credits: 10
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 6
enter course code to check: 200
course code exists.
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 7
course codes: ['100', '200', '300', '400', '500']
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 8
course details: [{'Title': 'maths', 'Faculty': 'sara', 'Credits': '10'},
{'Title': 'java', 'Faculty': 'anna', 'Credits': '20'}, {'Title': 'python',
'Faculty': 'issac', 'Credits': '30'}, {'Title': 'c program', 'Faculty':
'alice', 'Credits': '40'}, {'Title': 'biology', 'Faculty': 'joby',
'Credits': '50'}]
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 9
dictionary copied .
copied dictionary: {'100': {'Title': 'maths', 'Faculty': 'sara',
'Credits': '10'}, '200': {'Title': 'java', 'Faculty': 'anna', 'Credits':
'20'}, '300': {'Title': 'python', 'Faculty': 'issac', 'Credits': '30'},
'400': {'Title': 'c program', 'Faculty': 'alice', 'Credits': '40'}, '500':
{'Title': 'biology', 'Faculty': 'joby', 'Credits': '50'}}
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 10
all course records cleared.
==============
menu
[Link] a new course record
[Link] all course records
[Link] existing course details
[Link] a course using course code
[Link] for a course
[Link] if course code exists
[Link] all course codes
[Link] all course details
[Link] dictionary
[Link] all records
[Link]
enter your choice: 11
exiting program