New course! Every coder should learn Generative AI!
Try a free lesson0
A very basic question
In this code: Print(โsolve this math problemโ) X=int(input(โcalculate 99-76= โ)) If (x==23) Print(โcorrectโ) Else: Print(โincorrectโ) Type conversion is necessary else the code evaluates to โincorrectโ But in code: S=input(โ: โ) If s==q: Break No type conversion is necessary. Why?
3 Answers
+ 10
What is q? Did you mean "q"?
I think the default for input is string, that is why you need to convert it (correct me if I am wrong).
+ 3
The second code is not complete, is it?
If q (which could for example mean question) was a string, then there would be no conversion necessary, because s also is a string. Input always comes as string.
+ 1
yes the second code is not complete. i just wanted to know the difference for type conversion.
i ran this program:
s=input()
print(type(s))
and no matter if the input is an int, float or string, the output is always โstrโ.
thankyou for the help