greatchenny / Pyton_one

图灵学院
24 stars 20 forks source link

Basic calculator using python: #1

Open Karthik-a39 opened 2 months ago

Karthik-a39 commented 2 months ago

def add(x,y): return x+y def sub(x,y): return x-y def mult(x,y): return x*y def div(x,y): return x/y def expol(x,y): return x**y def calculator(): print("select the oparation") print("1.add") print("2.sub") print("3.mult") print("4.div") print("5.expol")

user=input("Enter the choice(1/2/3/4/5) : ")
print(user)
if user in['1','2','3','4','5']:
    num1=float(input("Enter the number: "))
    print(num1)
    num2=float(input("Enter the number: "))
    print(num2)

    if user=='1':
        print(f"{num1}+{num2}={add(num1,num2)}")
    elif user=='2':
        print(f"{num1}-{num2}={sub(num1,num2)}")
    elif user=='3':
        print(f"{num1}*{num2}={mult(num1,num2)}")
    elif user=='4':
        if num2!=0:
            print(f"{num1}/{num2}={div(num1,num2)}")
        else:
            print("number can't devided by Zero")
    elif user=='5':
        print(f"{num1} ** {num2}={expol(num1,num2)}")     
else:
      print("Error in user input")     

calculator()

Karthik-a39 commented 2 months ago

Super