Created
October 18, 2025 11:18
-
-
Save tjmonsi/fc867bacc439a4cc15f3308a82acfe1c to your computer and use it in GitHub Desktop.
Tries to teach while, if else, variables, and equation in one file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # initialization of variables | |
| x = None | |
| y = None | |
| while not isinstance(x, int): | |
| print(isinstance(x, int)) | |
| try: | |
| x = input("Add your first number: ") | |
| x = int(x) # try to force x as number | |
| except ValueError: | |
| print("Please put a valid number.") | |
| while not isinstance(x, int): | |
| print(isinstance(x, int)) | |
| try: | |
| y = input("Add your second number: ") | |
| y = int(y) # try to force x as number | |
| except ValueError: | |
| print("Please put a valid number.") | |
| choice = None | |
| choices = ["add", "subtract", "divide", "multiply"] | |
| while choice not in choices: | |
| choice = input("Type the option that you want to do for the two numbers: ") | |
| choice = choice.lower().strip() | |
| message = "" | |
| if choice == "add": | |
| z = x + y | |
| message = f"The summation of the two numbers are: {z}" | |
| elif choice == "subtract": # else if | |
| z = x - y | |
| message = f"The difference of the two numbers are: {z}" | |
| elif choice == "divide": | |
| z = x / y | |
| message = f"The division of the two numbers are: {z}" | |
| elif choice == "multiply": | |
| z = x * y | |
| message = f"The product of the two numbers are: {z}" | |
| print(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment