A very basic question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?

22nd Jan 2020, 4:43 PM
Harshit Jain
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).
22nd Jan 2020, 4:47 PM
๐Ÿ‡ Alex Tuศ™inean ๐Ÿ’œ
๐Ÿ‡ Alex Tuศ™inean ๐Ÿ’œ - avatar
+ 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.
22nd Jan 2020, 4:55 PM
HonFu
HonFu - avatar
+ 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
22nd Jan 2020, 5:00 PM
Harshit Jain