Q. Rewrite the following Python code after removing all syntax error(s). Underline the corrections done.


def main():

    r = input ('enter any radius:')

    A - pi * maths.pow (r, 2)

    Print ("Area = "+ a)

        Main()


Answer =

Correct code:-

import math
def main():
    r = float(input ('Enter any radius:- '))
    A = 3.14 * math.pow (r, 2)
    print ("Area = ", A)
main()
 


Output :-

Enter any radius:- 2.6
Area =  21.2264

>>>

Enter any radius:- 4
Area =  50.24

>>>

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. #TODO: Write the functions for arithmatic operations here
    #These functions should cover Task 2
    # Read the instructions

    # i will only do 2 functions, pls complete rest of it.
    # it shows all tests pass but you need to complete rest of function ('-','*','^','%')

    def add(a,b):
    return a+b

    def divide(a,b):
    try:
    return a/b
    except Exception as e:
    print (e)



    #-------------------------------------
    #TODO: Write the select_op(choice) function here
    #This function sould cover Task 1 (Section 2) and Task 3

    def select_op(choice):
    if(choice == '#'):
    reture -1
    elif (choice == '$'):
    return 0
    elif (choice in ('+','-','*','/','^','%')):

    #get first user input
    while (True):
    number1 = str(input("Enter first number: "))
    print(number1)
    #here check input numbers end with symbol #,$
    if number1.endswith('$'):
    return 0
    if number1.endswith('#'):
    return -1

    try:
    num1 = float(number1)
    break

    except:
    print("Not a Valid number,please enter again")
    continue
    # get second user input

    while (true):
    number2 = str(input("Enter second number: "))
    print(number2)
    if number2.endswith('$'):
    return 0
    if number2.endswith('#'):
    return -1


    try:
    num2 = float(number2)
    break

    except:
    print("Not a valid number,please enter again")
    continue

    if choice == '+':
    print(num1, "+" , num2, "=", add(num1,num2) )

    elif choice == '/':
    print(num1, "/" , num2, "=", divide(num1,num2) )

    # add rest of the calculation choice .....



    else:
    print("Something Went Wrong")
    else:
    print("Unrecognized operation")



    #End the select_op(choice) function here
    #-------------------------------------
    #This is the main loop. It covers Task 1 (Section 1)
    #YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE
    while True:
    print("Select operation.")
    print("1.Add : "+" ")
    print("2.Subtract : "-" ")
    print("3.Multiply : "*" ")
    print("4.Divide : "/" ")
    print("5.Power : "^" ")
    print("6.Remainder: "%" ")
    print("7.Terminate: "#" ")
    print("8.Reset : $ ")


    # take input from the user
    choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
    print(choice)
    if(select_op(choice) == -1):
    #programe ends here
    print("Done.Terminating")
    exit()



    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post