A very basic question | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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