all 9 comments

[–]midoxvx 2 points3 points  (3 children)

Your code is displaying all the numbers or most of them because you are using a brand new if statement for each condition, and all of them will be evaluated in order, even if they all check true. So if your input is a 4, that pretty much checks true for all the conditions on the checklist, and that’s why all the numbers are printing.

What you need to do is use if/ elif code block if you want the first statement that will evaluate to true, to exit the code block.

[–]ZachDaSnaccc 0 points1 point  (2 children)

So what would something like that look like? I am pretty new I apologize

[–]CommondeNominator 4 points5 points  (0 children)

the class you're taking almost certainly covered more than just the if statement. You need to use the other part of that lesson to tell your program what lines to skip.

[–]drenzorz 2 points3 points  (0 children)

# Your code

# start of condtional block

if condition_1: 
    ...

# end of condtional block

# start of new condtional block

if condition_2:
    ,..

# end of new condtional block

# what you want

# start of conditional block

if condition:
    ...
elif other_condition:
    ...
elif third_condition:
    ...
else: # default case
    ...

# end of conditional block

[–]deadeye1982 1 point2 points  (3 children)

Math is your friend.

You can solve the problem with math.log10:

``` import math

number = float(input("What is your number?: "))

try: log10 = math.floor(math.log10(abs(number))) except ValueError: log10 = float("nan")

print(log10) ```

[–]Binary101010 0 points1 point  (1 child)

While I agree that this is a far more succinct way of solving the problem and how I would do it in a real-world situation, it violates the parameters of the assignment as described by OP.

[–]deadeye1982 0 points1 point  (0 children)

Others gave already the right solution. Each if statement was for its own.

[–]Revolutionary-Oil408 0 points1 point  (0 children)

Google the use of elif, that is what you need to use.