Question

In: Computer Science

python Create a dictionary and insert several English words as keys and the Pig Latin (or...

python

  1. Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values.

  2. 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%.

  3. 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.

  4. 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.

  5. 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.

Solutions

Expert Solution

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


Related Solutions

C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console Pig Latin Translator This program translates a sentence and removes all punctuation from it. Enter a sentence: 'Tis but a scratch. Translation:      Istay utbay away atchscray Specifications Convert the English to lowercase before translating. Remove all punctuation characters before translating. Assume that words are separated from each other by a single space. If the word starts with a vowel, just add way to the...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to...
Create a program that translates English into Pig Latin. The function will take the first letter...
Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​ ############################################################# # translate() takes a single english word translates it to #pig latin...
Pig Latin is a language constructed by transforming English words. The following rules are used to...
Pig Latin is a language constructed by transforming English words. The following rules are used to translate English into Pig Latin: *If the word begins with a consonant, then all consonants at the beginning of the word, up to the first vowel are removed then added to the end of the word, followed by “ay”. For example, “computer” becomes “omputercay” and “think” becomes “inkthay”. *If the word begins with a vowel, then “way” is added to the end of the...
Create at least 25 random ISBN keys and insert all random ISBN keys into a Binary...
Create at least 25 random ISBN keys and insert all random ISBN keys into a Binary Tree. Write a function to determine if the Binary Tree is a BST or not a BST. In addition validate AVL balance condition. Hint: Should you proceed to validate AVL if the binary tree did not produce BST? Report the problems. You don’t need to fix anything. Also, do not hard code the tree inside the code. This needs to be done in Java.
Use python write a function that translates the input string into Pig Latin. The translation should...
Use python write a function that translates the input string into Pig Latin. The translation should be done word by word, where all words will be separated by only one space. You may assume that each word must have at least one vowel (a,e,i,o,u and uppercased counterparts), and there will be no punctuation or other special characters in the input string. The Pig Latin rules are as follows: For words that begin with consonants, all letters before the initial vowel...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules:...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules: For every word in a sentence, the firstletter of the word is shifted to the end of the word and the suffix “-ay” is added at the end of the word. For example, “hey pat”becomes “eyhay atpay”.Implement thepiglatin(str)function so it translates sentences to pig latin. If you have time remaining, try implementing afunction to ”decrypt” piglatin, i.e. given a sentence in piglatin, return the...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names to addresses. A person's name (stored as a string) will be the KEY and that person's address (stored as a string) will be the VALUE. 1.2) Insert into the dictionary 'addresses' the names and addresses of two (possibly imaginary) friends of yours. 1.3) Create a second empty dictionary called 'ages'. The dictionary you just created will map names to ages. A person's name (stored...
Using python. 1. How to create a dictionary that has an integer as a key and...
Using python. 1. How to create a dictionary that has an integer as a key and a byte as a value? the dictionary keys must contain integers from 0 to 255. It should be similar to UTF-8. When we enter an integer, it should return 1 byte. 2. Create a function when a user gives 1 byte, it should return the key from the previous dictionary.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT