def calculate():
"""
A simple calculator function that takes two numbers and an operation as input.
"""
try:
num1 = float(input("Enter the first number: "))
operation = input("Enter the operation (+, -, *, /, **): ")
num2 = float(input("Enter the second number: "))
if operation == '+':
result = num1 + num2
elif operation == '-':
result = num1 - num2
elif operation == '*':
result = num1 * num2
elif operation == '/':
if num2 == 0:
return "Cannot divide by zero"
result = num1 / num2
elif operation == '**':
result = num1 ** num2
else:
return "Invalid operation"
return result
except ValueError:
return "Invalid input. Please enter numbers only."
# Example usage
print(calculate())
Hi ahmedmohamedgebril20, welcome to Thunkable!
Be sure to check out How to ask Great Questions v2.0, the Community Guidelines, and our Getting Started Guide to make the best of your Thunkable Community experience!
Could you share a bit more about what you’re trying to do? Since Thunkable is a no-code platform for building mobile apps, you don’t need to post large chunks of code—we’ll be better able to help if you describe your goal or the problem you’re running into.
You might also find it helpful to search the Community for “Calculator apps” to see if others have already solved something similar.
1 Like