In: Computer Science
python
Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values.
Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%.
Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names as keys and ages as values. Your function should increment the age in the dictionary of each person whose birthday it is today.
Write a function called seniorList that takes as a parameter a dictionary that has names as keys and class years as values. Your function should return a list of names of students who are graduating in 2020.
Write a function called union that takes as parameters two dictionaries and returns a new dictionary with the entries of both. For common keys, take the value of the first dictionary.
1)def vowel(ch): # this function checks whether a character is a vowel OR NOT
a="AEIOUaeiou"
if ch in a:
return True
return False
def piglatin(s): # THIS CONVERTS ENGLISH WORD TO PIGLATIN
l=len(s)
i=-1
for j in range(len(s)):
if(vowel(s[j])): # CHECKING IF THERE IS VOWEL IN THE STRING
i=j
break
if(i==-1): #IF THERE IS NO VOWEL WE CANNOT CONVERT TO piglatin
return -1
else: #IF POSSIBLE THEN WE ARE SPLITTING AT THE VOWEL AND THE SECOND PART [i:]+ FIRSTPART [0:I]+"ay"
return s[i:]+s[0:i]+"ay"
d={}
l=["Hii","This","is","praneeth"]
for i in l: #FINDING piglatin WORD FOR EACH OF THE WORD IN LIST
res=piglatin(i)
if(res!=-1):
d[i]=res
print(d) #PRINTING DICTIONARY
2)
def bonus(d):
for key,value in d.items():
increased_amount = (value*5)//100 #caluculating increased amount
value+=increased_amount #adding it to the original salary
d[key]=value # changing the salary or updating the salary
return d
d={"Praneeth":10000,"Yeswanth":90000,"vamsi":60000,'vikas':60000}
res=bonus(d) #passing dictionary to bonus function
print(res) #PRINTING DICTIONARY
3)
def updateAge(l,d): #updating age method
for i in l:
age=d[i] #get the values of the person whose birthday is today
age+=1 #assigning and updating the age by one
d[i]=age
return d
d={"praneeth":20,"Yeswnth":90,"vamsi":65,'vikas':103,'krishna':19}
l=['praneeth','krishna']
res=updateAge(l,d)
print(res) #PRINTING DICTIONARY
4)
def seniorList(d): #seniorList method
res=[] #resultant list
for key,value in d.items():
if value==2020: #checking whether a person is graduated in 2020
res.append(key)
return res #returning the list
d={"praneeth":2020,"Yeswnth":2019,"vamsi":1998,'vikas':1030,'krishna':1976}
res=seniorList(d)
print(res) #PRINTING DICTIONARY
5)
def union(d1,d2):
res={}
for key,value in d2.items():
res[key]=value #in this we need not to check if the value is repeated or and for this case we are first adding all the values from the second dictionary then after we should insert elements from first dictionary
for key,value in d1.items():
res[key]=value
return res
d1={"praneeth":2020,"Yeswnth":2019,"vamsi":1998,'vikas':1030,'krishna':1976}
d2={"hiii":12,"praneeth":1000,"ravi":23,"vamsi":222}
res=union(d1,d2)
print(res) #PRINTING DICTIONARY