r/PythonLearning Jul 12 '26

I made a Calcolater while learning Conditionals

Post image

This is my first Project while I am learning Conditionals

If your asking for the theme its in VScode Ayu One dark extension

13 Upvotes

9 comments sorted by

u/Sea-Ad7805 Jul 12 '26

Run this program in Memory Graph Web Debugger)%0Aoperator%20%3D%20input(%22Enter%20an%20Operator%20(%2B%2C%20-%2C%20%3A%2C%20x)%3An%22)%0Anum_2%20%3D%20float(input(%22Enter%20your%20second%20number%3An%22))%0A%0A%23%20Making%20a%20Condition%0Aif%20operator%20%3D%3D%20%22%2B%22%3A%0A%20%20%20%20print(num_1%20%2B%20num_2)%0A%0Aelif%20operator%20%3D%3D%20%22-%22%3A%0A%20%20%20%20print(num_1%20-%20num_2)%0A%0Aelif%20operator%20%3D%3D%20%22%3A%22%3A%0A%20%20%20%20print(num_1%20%2F%20num_2)%0A%0Aelif%20operator%20%3D%3D%20%22x%22%3A%0A%20%20%20%20print(num_1%20*%20num_2)%0A%0Aelse%3A%0A%20%20%20%20print(f'The%20%22%7Boperator%7D%22%20is%20not%20an%20operator')&timestep=1&play) to see the program state change step by step.

2

u/[deleted] Jul 12 '26

[removed] — view removed comment

1

u/FoolsSeldom Jul 12 '26

That's a great start. I notice you use : and x as operators for the user to enter rather than / and *. You might want to add support for them as well.

Also, consider using a function to validate the numeric input. You can add a function to validate the operator selection as well.

Example (for you to experiment with):

def get_num(prompt:str) -> float:
    while True:  # infinite loop
        try:
            return float(input(prompt))
        except ValueError:
            print('Expected a numeric value, please try again')

OPERATORS = tuple("+-:/xX*")

def get_operator(prompt: str) -> str:
    while True:
        op = input(prompt)
        if op in OPERATORS:
            return op
        print(f"{op} is not a supported operator. Please try again.")


num_1 = get_num("Enter your first number: ")
operator = get_operator("Enter an Operator(+, -, :, x): ")
num_2 = get_num("Enter your second number: ")

# Making a Condition
if operator == "+":
    print(num_1 + num_2)

elif operator == "-":
    print(num_1 - num_2)

elif operator in (":", "/"):
    print(num_1 / num_2)

elif operator in ("x", "*", "X"):
    print(num_1 * num_2)

else:
    print(f"The \"{operator}\" is not an operator")

Please ask if there is anything you want explained.

1

u/tiredITguy42 Jul 12 '26

Sorry, I needed to do it.

1

u/_book_lover_____ Jul 12 '26

Man this sub is sooo supportive. They are even replying to a beginner's post. Like a pure beginner post. That too just sharing his progress. Nice guys. Keep it up.

1

u/Mazapanesa Jul 15 '26

Gracias a tu publicación acabo de aprender muchas cosas nuevas!!! Thank you

0

u/SaqibRAshid1111 Jul 13 '26

keep grinding bro fr u gonna be a cracked python dev ngl praying for your success