0

Why 7 == 7 is not true?

11th May 2017, 9:06 AM
Биба Биба
Биба Биба - avatar
9 ответов
+ 11
It is true. Type like this if 7==7: print("true") Don't forget indention
11th May 2017, 9:26 AM
Vaibhav Sharma
Vaibhav Sharma - avatar
+ 4
Hello! here is my explanation: num = 7 <---This is the given value *if num > 3: <----This is the 1st condition, if it´s not satisfied then the program goes to condition #2 print("3") *if num < 5: <---- This is the second condition,if not satisfied goes to condition #3 print("5") *if num ==7: <----This is the third and final condition. print("7") As we can note, the number given is 7 and 7==7 right? Mathematically it is true, but the "If" condition in the program evaluates the input in a logical way as I explained above: Value given, if condition #1 is true the program ends, if not then evaluates condition #2, and so on. Because the first condition is TRUE (7 is greater than 3) then the program ends and the result is 3 because that is the instruction( print("3")). *P.D. In fact we will never get to the final condition (7==7) because the program would end immediately in the first condition. *P.D. Sorry if I do not explain myself clearly.
19th May 2017, 4:31 AM
Pedro Andreu
Pedro Andreu - avatar
+ 3
according to me it is true. did you test this on the computer ?
11th May 2017, 10:14 AM
NimWing Yuan
NimWing Yuan - avatar
+ 2
if you get 7 from input and check it against 7, remember input by default is a string. If that is what you are doing, you would actually be checking "7"==7 which is false. couple ways to fix that, int(input()) for one will get the input as an integer.
11th May 2017, 9:51 AM
LordHill
LordHill - avatar
+ 2
It is true but in the last question the second indentation is false so the program doesnt pass to the next if statement
17th May 2017, 12:26 AM
max7564
max7564 - avatar
0
It should be True, could show your codes ?
11th May 2017, 9:26 AM
Damon RealMen
Damon RealMen - avatar
0
the output of that is 3 7 the reason being the first if statement is true. Num IS larger than 3 .. and the last if statement is true 7 does equal 7
16th May 2017, 1:07 AM
LordHill
LordHill - avatar
0
The result depend on the indentation: num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") Gives you an indentation error. num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") The outcome is 3. num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") The outcome is 3 and 7.
7th Jun 2017, 3:26 PM
Laszlo Kiss
Laszlo Kiss - avatar
- 1
What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") here's the code i tried it on the computer 7==7 is working and with indentation but then why is the answer 3
15th May 2017, 1:58 PM
Piali Chatterjee
Piali Chatterjee - avatar