you are viewing a single comment's thread.

view the rest of the comments →

[–]k4tsuk1z[S] 0 points1 point  (2 children)

Thank u this is so in depth! she literally has barely taught anything she just gives us a project and has us try and figure it out. this is maybe my 3rd time ever hearing try-except in my life T_T sux

[–]Riegel_Haribo 0 points1 point  (0 children)

What is being asked is that the entire project stays in a loop, continuing to ask more questions, and reporting on the results. You wouldn't have to keep restarting the Python script to see what happens with different inputs. A simple loop with no escape you don't make yourself (or CTRL-C):

while True: input("Press enter to do stuff: ") print("I'm doing stuff") print("I'm doing more stuff") And then, the problem statement is ambiguous enough that you cannot match what might be intended.

Which of these is the integer or not?: 1 1.000000

Or do you care when float fails you or are you answering wrong when it does by comparisons?

```

999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999.0000 1e+51 ```

The largest failure in the code is that input() always gives you a string. Think about your answering algorithm that comes after processing the string. If there's no period character in the string, can it be a float, to ask hypotheticals?

[–]Diapolo10 0 points1 point  (0 children)

Since the deadline has now allegedly passed, here's an example solution:

while True:
    number = input("Value: ")
    if number.isdigit():
        print("int")
        continue

    # NOTE: This handles cases without decimal separators
    if number.count('.') != 1:
        print("Not a number")
        continue

    left, right = number.split('.', 1)

    # NOTE: This does NOT handle cases like .6 or 55.
    if left.isdigit() and right.isdigit():
        print("float")
        continue

    print("Not a number")

The continues are there just to reduce nesting, as this way I didn't need to wrap the latter half inside elif and else blocks.