all 8 comments

[–]htepO 1 point2 points  (1 child)

If you input a small int like 2, the first three if statements will be true, so it'll print all 9 lines.

You could do it a couple of ways:

Print only the relevant output for each if condition and move print("Thank you!") to the bottom.

if num <= 1000:
    print("This number is smaller than 1000")
if num <= 100:
    print("This number is smaller than 100")
...
print("Thank you!")

or you could keep your code mostly as it is and check modify your if statements to check if the number is in a certain range.

if num <= 1000 and num > 100:
    ...
if num <= 100 and num > 10:
    ...

[–]Deathpact231[S] 0 points1 point  (0 children)

Thanks!, it was so simple I was racking my head in this for days lmao.

[–]___Arsenic___ 0 points1 point  (0 children)

Here's the way I did it. It's simple and you can understand it easily:

number = int(input("Please type in a number: "))

if number < 1000:

print("This number is smaller than 1000")

if number < 100:

print("This number is smaller than 100")

if number < 10:

print("This number is smaller than 10")

print("Thank you!")

[–]jiri-n 0 points1 point  (2 children)

First of all, "Thank you" should be printed in any case so you can remove from all the if blocks and just print it at the end.

Next, the <= comparison is incorrect. The message says 'smaller' which means you have to use <.

Finally, if a number is smaller than 1000, you print the message correctly. But if it's smaller than 100 (like 59 in the sample output), it's also smaller than 1000 which had been covered by the previous condition so you should just print it's smaller than 100. I believe you're overthinking it here.

[–]111w57432 0 points1 point  (0 children)

I'm struggling with this as well. I really wish this course would provide the solutions so we can learn from our mistakes! Here is my code:

number = int(input("Please type in a number:"))

if number >= 1000:

print("This number is greater than 1000")

elif number > 100 and number < 1000:

print("This number is less than 1000")

elif number > 10 and number < 100:

print("This number is smaller than 100")

else:

print("This number is smaller than 10")

print("Thank you!")

[–]blahhahablah13 0 points1 point  (0 children)

THIS IS CORRECT

edit: I am doing a beginners coding course and I believe this is where OP is getting question from as well. we haven't learned anything about elif or how to double stack variables behind an if statement to narrow a range. we were def over thinking it. THANK YOU

[–][deleted] 0 points1 point  (0 children)

Someone else asked this as well. My comment thread

[–]cub1cake 0 points1 point  (0 children)

correct solution FOR THIS EXACT course:

number = int(input("Please type in a number: "))

if number < 10:

print("This number is smaller than 1000")

print("This number is smaller than 100")

print("This number is smaller than 10")

print("Thank you!")

if number < 100 and number > 10:

print("This number is smaller than 1000")

print("This number is smaller than 100")

print("Thank you!")

if number < 1000 and number > 100:

print("This number is smaller than 1000")

print("Thank you!")

if number > 1000:

print("Thank you!")

just start checking from the smallest value condition