Akash Kalita 11802733 Ca2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CA-2

Name-: Akash Kalita reg no. 11802733


Q1. Suppose there is two different types of dictionary, one dictionary contains
employee id and name of employee and another dictionary contains employee
id and salary. Take 5 employee details. Now display the employee's
designation from the following condition: If salary between 80,000 to 90,000:
designation: Project Manager salary between 70,000 to 80,000: designation:
Team Leader salary between 60,000 to 70,000: designation: Software
Developer salary between 50,000 to 60,000: designation: Software Trainee
Display result in the form of dictionary.
Solution-:
print("**Enter details of Employee**")#print statement
d1={}#d1,d2 empty dict
d2={}
for q in range(2): # for loop for taking values from user
print("Enter id")
id=int(input())
print("Enter name")
name=input()
print("Enter salary")
sal=int(input())
d1.__setitem__(id,name)#__setitem__ is a method used for assigning a
value to an dict= d1 and d2.
d2.__setitem__(id,sal)
for q in d2: # for loop for checking condition
if d2[q]>=80000 and d2[q]<=90000:
print({q:"Project Manager"})
elif d2[q]>=70000 and d2[q]<=80000:
print({q:"Team Leader"})
elif d2[q]>=60000 and d2[q]<=70000:
print({q:"Software Developer"})
elif d2[q]>=50000 and d2[q]<=60000:
print({q:"Software Trainee"})

OUTPUT-:
Q2. Write a program that computes the net amount of a bank account based
on a transaction. The transaction format is shown as following: D 100 W 200
Here, D means deposit while W means withdrawal. Take the following input in
the form of dictionary: D 300 D 300 W 200 D 100
{"D":300,"D":300,"W":200,"D":100} Then, the output should be: 500
Solution -:
def amount(trans):#This function amount to the trans passed in as a parameter
aamount=0
for i in trans:#For loop for checking debit and withdrawal
if(i[0]=='D'):
aamount = aamount+int(i[2::])
elif(i[0]=='W'):
aamount = aamount-int(i[2::])
return aamount
trans=["D:300","D:300","W:200","D:100"] # dictionary of data
print("amount-:",amount(trans))# return amount

OUTPUT-:
Q3. You are required to write a program to sort the (name, age, height) tuples
by ascending order where name is string, age and height are numbers. Take
inputs from user by a sequence of comma-separated. Then ask options for sort
to follow the following criteria:
1: Sort based on name;
2: Then sort based on age;
3: Then sort by height.
Solution-:
print("Enter number of persons")
t=[]
for w in range(int(input())): #for loop for asking for number of person
print("Enter name,age & height separated by comma")
t.append(tuple(x for x in input().split(',')))#entering data seperated by
comma
print("Enter sort type")
print("1: Sort based on name")
print("2: Sort based on age")
print("3: Sort by height")
choice=int(input()) #switch case for asking condition
if choice==1:
t=sorted(t,key=lambda s: (s[0])) #lambda is used to create anonymous
function
elif choice==2:
t=sorted(t,key=lambda s: (s[1]))
elif choice==3:
t=sorted(t,key=lambda s: (s[2]))
print(t)
OUTPUT-:
BY NAME

BY AGE
BY HEIGHT

You might also like