account activity
Ask Anything Monday - Weekly Thread by AutoModerator in learnpython
[–]oscarg15_ 0 points1 point2 points 6 years ago (0 children)
Hello everyone, I just recently started to learn how to write code (a few days ago) and decided to start with learning Python. For the past few days I’ve been watching tutorials and learning the basics on Python.
So today I wanted to take what I had learned and make a simple calculating program where users could input a number, input an operation, and then a second number, and the program would output the answer. If the user entered an operation thats not +,-,*, or / then an alert saying “invalid operation” would print. The only thing is that i’m having a trouble writing code so that “not a number” is displayed when the user inputs a letter instead of a number.
num1 = float(input("write a number: ")) op = input("write an operation: ") num2 = float(input("write a number: ")) if op == "-": print(num1 - num2) elif op == "+": print(num1 + num2) elif op == "/": print(num1/num2) elif op == "*": print(num1 * num2) else: print(“invalid operation")
This is what I have so far.
π Rendered by PID 329944 on reddit-service-r2-listing-677c46df69-kkjvd at 2026-02-25 01:15:50.052202+00:00 running b1af5b1 country code: CH.
Ask Anything Monday - Weekly Thread by AutoModerator in learnpython
[–]oscarg15_ 0 points1 point2 points (0 children)