Python: Design a straightforward mini-computer utilizing if elif (simply like switch case)

Python if else example: here, we are going to actualize program to structure a straightforward adding machine utilizing if, elif proclamations in Python that will perform include, subtract, increase and gap tasks.

Python if else example: here, we are going to actualize program to plan a basic mini-computer utilizing if, elif explanations in Python that will perform include, subtract, duplicate and partition tasks.

Example:

    Message:
    Calculator 
    1.Add
    2.Substract
    3.Multiply
    4.Divide

    Input:
    Enter Choice(1-4): 3
    Enter A:10
    Enter B:20

    Output:
    Product =  200

Program:

# menus
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")

Output:

Calculator
1.Add
2.Substract
3.Multiply
4.Divide
Enter Choice(1-4): 3
Enter A:10
Enter B:20
Product =  200

Leave a Comment

error: Alert: Content is protected!!