+ 2
I am not getting correct output....
run my code and enter a decimal number ..then see... There is a problem... My code is not getting correct output.... https://code.sololearn.com/c3p2zeVOBHJX/?ref=app
4 Réponses
+ 3
Shubham Raj
When you take input then it is considered as string so if you enter 1.5 then it would be string but 1.5 contains decimal so you need to cast input with float and if you cast with int, you will get error.
print this and see.
print (type(a))
If you cast input with float then definitely type of input would be float so no need to check type after converting in float.
+ 1
A͢J
Yeh!
I understand.....
Can I use only string in input ..???.
I mean if i will use
var = input('enter number')
And then i can convert into string to float or integer using this
int() or float()
Does this is correct ??
+ 1
Shubham Raj
Some languages bydefault gives input in string. It is a default nature of input.
We have to convert according to data types. To convert in int use int() function, to convert in float use float () function
+ 1
Yeh !!
A͢J
I know these things...
But I am new here 😅 so sometime it is difficult for me ....
Var input ('number')
Output = string
Var int(input ('number'))
If input = integer..
Output= integer
If input = float
Output = error
Error if input is a float ..
Var float(input ('number'))
Output = float
No error
If input = interge
Output = int.0
If input = float
Output = float
Am I correct???
yeh we can convert string into integer and float ..
for float = float()
for integer= int()