Why do they use programs with incorrect logic as their examples? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do they use programs with incorrect logic as their examples?

For example: num = 12 if num > 5: print("Bigger than 5") if num <=47: print("Between 5 and 47") This code would seem ok to a beginner, but if you type four, it would still say: between 5 and 47. WHy would you use a program that would make no sense for a good program to show beginners how to program? They could have made it a two ending story, something that would spark interest, or at least be a decent program.

11th Apr 2017, 4:49 PM
darian brown
darian brown - avatar
3 Answers
+ 6
There is no way this program prints "Between 5 and 47" for num = 4
11th Apr 2017, 5:12 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
@Darian brown reconsider the importance of indents (spaces) in python. the logic is correct.
11th Apr 2017, 7:52 PM
seamiki
seamiki - avatar
0
if num <=47: print("Between 5 and 47") only runs when the first if is true, because it is also indented
12th Apr 2017, 1:23 PM
Dion Niessen
Dion Niessen - avatar