Here, we will create a Calculator in Python using if else as decision conditions. It will be a good exercise to get us started using Python in practice.
Open your text editor and create a new Python file.
The calculator we are going to create will perform only 4 operations, which will be addition, subtraction, multiplication and division.
# Menu
print("Enter:\n\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n")
choice = input("Enter choice: ")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
if choice == '1':
print(a + b)
elif choice == '2':
print(a + b)
elif choice == '3':
print(a + b)
elif choice == '4':
print(a + b)
else:
print("Invalid choice")
Output:
Enter:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter choice: 2
Enter the first number: 3
Enter the second number: 2
5
Post a Comment
0Comments