I can't understand how the program is running | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
+ 6

# I can't understand how the program is running

12th Nov 2020, 12:29 PM
Antony Praveenkumar M
17 Antworten
+ 4
example: x = 1 + 1 y = 2 if x == y: print('True') else: print('False') This will print 'True' the if statement will not occur if the condition is false, the else statement occur.
12th Nov 2020, 12:36 PM
noteve
+ 3
Input consider as a string???
12th Nov 2020, 12:44 PM
Antony Praveenkumar M
+ 2
'print' not 'Print' and n = int(input())
12th Nov 2020, 12:39 PM
noteve
+ 1
n=input () if n==5: Print ('true') else: print('false') The question is even though I put 5 the results show false why?????
12th Nov 2020, 12:38 PM
Antony Praveenkumar M
+ 1
Ok that's not a problem
12th Nov 2020, 12:40 PM
Antony Praveenkumar M
+ 1
Just run the program and put 5 and see what will happen
12th Nov 2020, 12:41 PM
Antony Praveenkumar M
+ 1
Input operation consider the value as string whatever I put correct As I'm correct
12th Nov 2020, 12:45 PM
Antony Praveenkumar M
+ 1
Thank u so much
12th Nov 2020, 12:48 PM
Antony Praveenkumar M
+ 1
if statement : if a condition is satisfied such as (if 2==2 : print("true")) else statement : if a condition is not satisfied
13th Nov 2020, 1:16 PM
Somil Khandelwal
0
12th Nov 2020, 12:33 PM
noteve
0
try to review the sololearn lessons again and experiment until you understand it. Happy coding!
12th Nov 2020, 12:40 PM
noteve
0
It's always show's false
12th Nov 2020, 12:41 PM
Antony Praveenkumar M
0
try this n=int(input ()) if n==5: print ('true') else: print('false')
12th Nov 2020, 12:42 PM
noteve
0
input () Operation work in if statement?????????
12th Nov 2020, 12:42 PM
Antony Praveenkumar M
0
Yes it's working how
12th Nov 2020, 12:43 PM
Antony Praveenkumar M
0
because the 5 youre trying to type is a string not an integer, you must convert it first to integer by adding int befor the number int(x)
12th Nov 2020, 12:45 PM
noteve
0
The input you are giving is always a string, and Python does not convert it to an integer. So you must explicitly convert the string to an integer, as said by The Zen of Python:"Explicit is better than implicit".
13th Nov 2020, 2:40 AM
Boay.JS