Question

In: Computer Science

magine a table is given as following. This table is called lookup table. The table works...

magine a table is given as following. This table is called lookup table. The table works as following. It assigns a number to some uppercase or lowercase alphabents as shown in the table.

A B F M N P Q W Z

letter

number

letter

Number

12

e

8

  

10

f

3

  

5

i

2

  

4

m

0

  

0

n

1

  

11

p

2

  

10

q

3

  

9

r

4

  

9

s

5

      

  1. 1- Design and implement a function with 2 parameters: 1- a string (a word) 2- a variable that represents the above lookup table. The function converts the string to a number and returns it. This function replaces each character in the string with its corresponding number from the above table. If the character does not exist in the above table, the function replaces it with 0. The function will eventually return the number.

  2. 2- Define a main function and call the method you designed in 1. When calling the above function in the main method, pass to the function the word “We have missed Vancouver’s summer” and the above lookup table. What is the output of the function for the this word, “We have missed Vancouver’s summer” ?

  3. python code

Solutions

Expert Solution

# Code for part 1
def conversion(string,table):
#the given word is stored in variable string and the table is stored in variable table
    s="" # An empty string is declared to store the resultant string
    for ele in string: # iterates through every character in the string
        if ele in table.keys(): # if the character is present as the key in the dictionary in which we store the table
            s=s+str(table[ele]) # then the values is converted to string and concatenated to resultant string
        else:# if the character is not present
            s=s+'0' # then "0" is concatenated
        
    return int(s) # resultant string after conversion is converted to number and is returned
# Code for part 2           
def main():
    # call to conversion function and the word is passed as first argument,the table is stored as dictionary and passed as second argument 
    s=conversion("We have missed Vancouver's summer",{'A' : 12 ,'B' : 10,'F' :5 ,'M' :4 ,'N' :0 ,'P' :11 ,'Q' :10 ,'W' :9 ,'Z' :9,
    'e':8 ,'f' : 3,'i' :2 ,'m' :0,'n' :1 ,'p' :2 ,'q' :3 ,'r' :4 ,'s' :5 }) 
    print(s) # prints the number we obtained after conversion
if __name__ == "__main__":
    main() # call to main function

OUTPUT:

Please comment if you have any doubts.

Rate Please!!!!!!!


Related Solutions

In C 1- Use nested for loops to create an addition lookup table. Fill in an...
In C 1- Use nested for loops to create an addition lookup table. Fill in an array and print out the following table showing the sum of the row and column numbers 0-9. 0 1 2 3 4.. <- column numbers 1 2 3 4 5.. 2 3 4 5 6.. <- These nos. = Row + Column 3 4 5 6 7.. <- for example 7 = 3 + 4 4 5 6 7 8.. ... ^Row numbers 2-...
1.) Explain how to calculate the amount financed, financecharge, and APR by table lookup. Do...
1.) Explain how to calculate the amount financed, finance charge, and APR by table lookup. Do you think the Truth in Lending Act should regulate interest charges?  
Given is a Python program that connects to a sqlite database and has one table called...
Given is a Python program that connects to a sqlite database and has one table called writers with two columnns: name - the name of a writer num - the number of works the writer has written The writers table originally has the following data: name, num Jane Austen,6 Charles Dickens,20 Ernest Hemingway,9 Jack Kerouac,22 F. Scott Fitzgerald,8 Mary Shelley,7 Charlotte Bronte,5 Mark Twain,11 Agatha Christie,73 Ian Flemming,14 J.K. Rowling,14 Stephen King,54 Oscar Wilde,1 Update the Python program to ask...
Given the following conditional value table:
Given the following conditional value table:AlternativesVery Favorable MarketAverage MarketUnfavorable MarketBuild new plant$250,000$180,000-$200,000Subcontract$270,000$185,000-$220,000Overtime$100,000$50,000-$12,000Do Nothing$0$0$0a) Using the decision making under uncertainty with the criterion of MaximaxThe appropriate decision will be SubcontractThe value of the return under this decision is $ 270.000. b) Using the decision making under uncertainty with the criterion of MaximinThe appropriate decision will be Do NothingThe value of the return under this decision is $ 0. c) Using the decision making under uncertainty with the criterion of Equity Likely.The appropriate decision...
Given the following events in the table below and knowing that they are provided for a...
Given the following events in the table below and knowing that they are provided for a four stroke, spark-ignition engine running at 2500 RPM, please fill out the missing information. Note that: BTDC=before top dead center, ATDC=after top dead center, ABDC=after bottom dead center, BBDC= before bottom dead center. Process Event Duration (crank angle) Duration(ms) Intake 15 ˚BTDC to 60 ˚ABDC Compression BDC to 30 ˚BTDC Combustion 30 ˚BTDC to 30 ˚ATDC Expansion TDC to BDC Exhaust 60 ˚BBDC to...
A hash table works as follows. We allocate a table of m slots. All the items...
A hash table works as follows. We allocate a table of m slots. All the items we intend to store in the table belong to a large set U of items. We adopt a function f: U ->{0,1...m-1) which maps an item to a slot. Suppose we seek to store n items from U in a table of m slots. (a) Suppose f maps every item in U with equal probability to one of the m slots. What is the...
Given the following table of x and y values, test the claim that there is a...
Given the following table of x and y values, test the claim that there is a linear correlation. Use a .05 significance level. x|12 10 9 7 8 y | 182 169 155 140 144 For this particular problem, here’s the information you need to include: Step 1 Ho= Ha= Step 2 Signifcance level a= Step 3 Test: p-value: Step 4 Conclusion (Yes/No): Is there sufficient evidence to conclude that there is a linear correlation? 8. Find the regression equation...
The results of a standard Proctor test are given in the following table. a) Determine the...
The results of a standard Proctor test are given in the following table. a) Determine the maximum dry unit weight of compaction and the optimum moisture content. Given: Mold volume = 1/30 ft3. b) Determine the void ratio and the degree of saturation at the optimum moisture content. Given: Gs = 2.69. Trial no. Weight of moist soil in the mold (lb) Moisture content (%) 1 3.7 8.6 2 4.15 10.6 3 4.69 12.5 4 4.62 14.9 5 4.02 16.7...
Answer the next question on the basis of the information given in the following table.                            &
Answer the next question on the basis of the information given in the following table.                                                                                     2 points Employment Total Product Product Price 0   0 $3 1 12 3 2 22 3 3 30 3 4 36 3 5 40 3 6 42 3 If the firm is hiring workers under purely competitive conditions at a wage rate of $22, it will employ
Define an inducible transgenic and given an example of how it works.
Define an inducible transgenic and given an example of how it works.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT