Can we put float or non-integral values while inputting it from user side and convert the final output of the two no.s?? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
0

Can we put float or non-integral values while inputting it from user side and convert the final output of the two no.s??

I am suggesting like this if anyone can help me because it states that if non-integral value or float passed as an input it can cause error. Below is the example which I did work upon it executed without any error: >>>float(input("Enter a:")) + float(input("Enter b:")) Enter a: 40.0 Enter b:3.5 43.5 Please can anyone clear my doubt???

24th Jul 2019, 1:59 PM
Vyoma Patel
Vyoma Patel - avatar
6 Respostas
+ 2
float(input()) tries to convert your input, which is of string format, to float. If you write '40.0', that works, because Python can understand it as a float. But if you write '40.z', you will get an error, because that string doesn't make sense as a float.
24th Jul 2019, 2:06 PM
HonFu
HonFu - avatar
+ 1
Hey HonFu [#GoGetThatBugChamp!] Actually asked about numbers so there z can't be put and I also put 3.5 as an input value so python considers float but in that lesson they mentioned that we can't take float or non-integral values as it can cause error so then can you explain it once again??
24th Jul 2019, 2:16 PM
Vyoma Patel
Vyoma Patel - avatar
0
I just looked it up. I think it is sloppily written. They seem to mean this: non-(integer or float)
24th Jul 2019, 2:19 PM
HonFu
HonFu - avatar
0
But, then which numerical values can't be considered and cause an error??
24th Jul 2019, 2:21 PM
Vyoma Patel
Vyoma Patel - avatar
0
They just mean, that the string has to come in a shape that is recognizable as an int or a float, and not something like 'shulrtzg'.
24th Jul 2019, 2:27 PM
HonFu
HonFu - avatar
0
Okay as per your answer it is clear that all numerical values are accepted except string values Thanks
24th Jul 2019, 2:29 PM
Vyoma Patel
Vyoma Patel - avatar