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