Mustafa-Cyberrr / Project1

Just trying something. :/
0 stars 0 forks source link

Python Calculator #1

Open Mustafa-Cyberrr opened 2 years ago

Mustafa-Cyberrr commented 2 years ago

I want to make a normal working calculator in python using While loop. I tried doing it and it was very hard and beyond me. You can use if, elif and else and anything else and I'd appreciate if the code is made by yourself and no modules imported. Also, one of the requirements is to get the user to choose as many numbers they want, the operator they want and break the loop when they want. Thanks.

sichiiii commented 2 years ago
print("Calculator")
print("1.Add")
print("2.Substract")
print("3.Multiply")
print("4.Divide")

# input choice
ch=int(input("Enter Choice(1-4): "))

if ch==1:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a+b
    print("Sum = ",c)
elif ch==2:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a-b
    print("Difference = ",c)
elif  ch==3:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a*b
    print("Product = ",c)
elif ch==4:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a/b
    print("Quotient = ",c)
else:
    print("Invalid Choice")