Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conditional Branching
# Studying conditional Branching
#refer: conditional branching.txt
#see: elif.png
# Basic Arithmatic Calculator
Number1 = int(input('Enter the First Number: '))
Number2 = int(input('Enter the Second Number: '))
# Menu
print("1. Addition: ")
print("2. Substraction: ")
print("3. Multiplication: ")
print("4. Division: ")
choice = int(input('Enter your Choice: '))
# Calculation
if choice == 1:
ans = Number1 + Number2
print('➜ ', Number1, ' + ', Number2, ' = ', ans)
elif choice == 2:
if Number1 >= Number2:
ans = Number1 - Number2
print('➜ ', Number1, ' - ', Number2, ' = ', ans)
else:
ans = Number1 - Number2
print('➜ ', Number1, ' - ', Number2, ' = ', ans)
elif choice == 3:
ans = Number1 * Number2
print('➜ ', Number1, ' * ', Number2, ' = ', ans)
else:
try:
ans = Number1 / Number2
print('➜ ', Number1, ' / ', Number2, ' = ', ans)
except:
print('➜ Not possible!!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment