0
why when i enter that code get '102' and not 12.0 the code is: input("enter a number: ") + input ("enter another number: ") enter a number: 10 enter another number: 2 why i get '102'. and not 12
i know that i can enter int(function) or float but i wanna to understand why the output is 102
4 odpowiedzi
+ 3
You concatenated the two strings. Don't forget that input () on its own returns a string value. So for the first input, you entered 10. The input function returns it as a string. The second when you entered 2 is returned as a string too. So when you use the + operator on two strings it concatenates them.
"10"+"2" becomes "102". If you want the values to be treated as numbers, you must convert the result from the input to an integer using int () or float () if you want the value to be a decimal number.
+ 1
because the program uses 10 and 2 as strings, not as ints. It is simply putting "10" and "2" together to form "102" instead of doing 10+2=12
+ 1
Input is interpreted like a str string, the + command join the two str, no the logical operation of addiction 1+1
0
thanks alot guys :)