Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simply Calc v2
#1
Hi Everyone!

I am new to this but I have seen calculators demo but I am trying to make an easier one to cheese for any symbol.
I am trying not to use Boolean!


Why is this not working:
num1 = input("Enter a number: ")
symbol = input("input symbol: ")
num2 = input("Enter a number: ")

result = float(num1) + symbol + float(num2)

print(result)
Many Thanks

Tom
Reply
#2
use an fstring:
result = f"{float(num1)} {symbol} {float(num2)}"
Reply
#3
I think he wants the result displayed, rather than the entered text.

eval() is risky, and should only be used if you can control its use. That said, this works:
num1 = input("Enter a number: ")
symbol = input("input symbol: ")
num2 = input("Enter a number: ")
st = num1+symbol+num2
print(eval(st))
Output:
Enter a number: 4 input symbol: * Enter a number: 3 12
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to automate sending bulk emails from an excel file or a calc-file apollo 0 2,749 Dec-10-2020, 08:43 PM
Last Post: apollo
  Complete Beginner Startup - Simply run github code for hpd20 Image_Engine 8 4,692 Apr-23-2018, 11:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020