-2

I'm a beginner in programming and I'm trying to write a calculator code. I had a problem with the outputs because I give the input as an str with StringVar(), but this prevents me to do decimal divisions such as a simple "54/10" for example. Is there a way to convert my string into a float to avoid such a limit??? I copy the all code down so everybody can have a read and correct any mistake. Thanks

[Code][1]
  • [Do not post images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). Do not make it hard for us to help you. – Jongware Apr 19 '20 at 20:53

1 Answers1

0

You did not actually posted your code, what you posted.

You are making a confusion. The following code works with float variables as stings so to speak.

my_float = float("12.45")
print(my_float)

Your example 52/10 is not a valid float in computer terminology. Depending on the complexity of your code you can fix this with a string.split("/") and work with each number separately or use a Reverse Polish notation convertor and the calculator (https://en.wikipedia.org/wiki/Reverse_Polish_notation).

You need to read up a bit before attempting the second version, and I would recommend some simple Python online tutorials that also teach Computer Science basics.

abarbatei
  • 46
  • 5