#π Calculator
14 messages Β· Page 1 of 1 (latest)
@rough pine
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
def menu():
print("Menu")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("")
menu_option = input("Please input a valid menu number: ")
num1 = input("Please input first number: ")
num2 =input("Please input second number: ")
if menu_option == 1:
addition(num1, num2)
if menu_option == 2:
subtraction(num1, num2)
if menu_option == 3:
multiplication(num1, num2)
if menu_option == 4:
division(num1, num2)
def addition(num1, num2):
sum = num1 + num2
print(sum)
pass
def subtraction(num1, num2):
sub = num1 - num2
print(sub)
pass
def multiplication(num1, num2):
times = num1 * num2
print(times)
pass
def division(num1, num2):
if num2 != 0:
divide = num1 + num2
print(divide)
pass
menu()
Heres what it gave me when I gave it input of 1s
Menu
- Addition
- Subtraction
- Multiplication
- Division
Please input a valid menu number: 1
Please input first number: 1
Please input second number: 1
Process finished with exit code 0
you have to cast the inputs to int
when you input 1 for the menu number you actually get "1" which is not equal to 1 (same goes for the other inputs)
menu_option = int(input("Please input a valid menu number: "))
num1 = int(input("Please input first number: "))
num2 = int(input("Please input second number: "))
Lol im so dumb, cheers it works now
π
how do you end ther channel
You can type !close on a blank line @rough pine
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.