Answer to Question #242185 in Computer Networks for hussain

Question #242185

1.  Implement a Command Interpreteron apollo for the following commands. Note that each command follows a different pattern:  

c.help  cmd1  cmd2 cmd3 ...

i.       The command helpby itself should list the names of all the commands supported by your program and only the names.

ii.      Extend the parallel data structure of command names and methods used in the example code to include a 3rd field containing a short help message. If the help command arrives with additional tokens display the help for each command listed..

d.     sumsqnum1 num2 num3

Squares each number sums the result.  Returns the sum and the square root of the sum as output. The numbers should be converted from their string values to doubles to do the calculation.  If no numbers are listed result should be 0.0 0.0..



1
Expert's answer
2021-09-26T11:41:41-0400
import sys
while 1:
    help=input(">>>")

    if help=='exit':
        break
    try:
        y=eval(help)
        if y:
            print('Enter cmd1 for addition')
            print('Enter cmd2 for substraction')
            print('cmd3- for multiplication')

            cmd=input('Enter command')
            cmd1=eval(cmd)
            cmd2 = eval(cmd)
            cmd3 = eval(cmd)
            if(cmd=='cmd1'):
                if cmd1:
                    num1=input('Enter num1')
                    num2=input('Enter num2')
                    sum=eval(num1,num2)
                    if sum:
                       print(num1+num2)
            if cmd=='cmd2':
                num1 = input('Enter num1')
                num2 = input('Enter num2')
                sum = eval(num1, num2)
                if sum:
                    print(num1 - num2)
            if cmd=='cmd3':
                num1 = input('Enter num1')
                num2 = input('Enter num2')
                sum = eval(num1, num2)
                if sum:
                    print(num1 * num2)

    except:
        exec(help)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS