-3

I've created a basic script with Input options, but I'm not sure how I can get a simple addition with decimal numbers like 1.2 + 2.3

To this point I'm using

value1 = int(input("Choose one Number"))
value2 = int(input("Choose another Number"))

But these are only numbers without decimal points. Is there any option to use decimal point numbers?

Thanks in advance

Lorenzo Mogicato
  • 138
  • 1
  • 11
Rekoran
  • 7
  • 1
  • 3
    Use [`float`](https://docs.python.org/3/library/functions.html#float) instead of `int`? – DeepSpace Jul 31 '22 at 09:42
  • 1
    Normally a dot is used to separate the integral and fractional part. If you are coding for users which use a comma, then the fist thing you need to do is to convert the comma to a dot. `float(input("choose one number").replace(",", "."))` – Daniel F Jul 31 '22 at 09:56
  • 1
    I would strongly recommend that you follow some good tutorial, this is the kind of things that you will learn by doing that - and note that SO is really not meant to replace that. You can find a list at https://sopython.com/wiki/What_tutorial_should_I_read%3F . Also, reading the documentation (the official Python doc is very well made) will let you discover lots of useful things... – Thierry Lathuille Jul 31 '22 at 10:27

1 Answers1

0

after receiving the input from the user you could convert it to float instead of int this should do the trick :

value1 = float(input("Choose one Number"))
value2 = float(input("Choose another Number"))

for value1=2.5 and value2=3.2 the output was :

5.7

if you have any questions feel free to ask me in the comments :) and if my comment helped you please consider marking it as the answer

Ohad Sharet
  • 1,097
  • 9
  • 15
  • Thanks for ur advice, but when i try it the float still stays purple and it gives me an error. Is there any option that i can input my code here like u did? Sorry for the questions, but this is as i mentioned my first time using stackoverflow.. – Rekoran Jul 31 '22 at 09:54
  • yes, there is a way, after you paste your code to your post, just mark all of it and press Ctrl+k :) and if you could also past the error that you are receiving that would be grate – Ohad Sharet Jul 31 '22 at 10:04