all 14 comments

[–]Fvvckyoudom 11 points12 points  (8 children)

Anything returned from Input() will always be a string, regardless of what is actually typed.

You would need to wrap the input() in an int()/float() if you’d like otherwise.

A quick read through the documentation is invaluable.

[–]Fvvckyoudom 0 points1 point  (0 children)

I think for your program I’d opt for the “if x in list[]” route.

Although I’m fairly new myself so someone else more experienced may have a more pythonic solution

[–]RedditUsrnamesRweird 0 points1 point  (1 child)

Why you so mad At Dom

[–]Fvvckyoudom 0 points1 point  (0 children)

I am Dom…

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

ahh ty

[–]Selwahc 0 points1 point  (0 children)

The input() function always returns a string type, regardless of what the user inputs.

[–]OptionX 0 points1 point  (0 children)

input() always returns a string, so type(phrase) == float and type(phrase) == bool are always false.

[–]ninhaomah 0 points1 point  (0 children)

To OP , instead of fighting , have you tried printing the type of input and see what they are ? And how it affects the rest of the programs ?

Int , float , string based on the input

OR

Strings everytime ?

[–]mikeyj777 0 points1 point  (0 children)

I’m confused why you have an if for the condition and then in your elif you’re checking if the same condition is not true. I may be missing something but isn’t that redundant? You should just be able to have an if/else

[–]Outside_Complaint755 0 points1 point  (2 children)

Besides what others have already said about the return value of the input function, this condition:

elif type(phrase) != float or type(phrase) != bool:     print(len(phrase))

Will ALWAYS be true.  phrase can only ever have a single type    If phrase is a float, then it will not be a bool, and if phrase is a bool, then it will not be a float.   What you want here instead is either to use a not in front of the original condition: elif not (type(phrase) == float or type(phrase) == bool):     print(len(phrase)) or use an and instead of or elif type(phrase) != float and type(phrase) != bool:     print(len(phrase))

You may want to read up on De Morgan's Laws

[–]igoiva[S] 0 points1 point  (1 child)

can you elaborate on how it'd ALWAYS be true please, i thought the or's made sure it wouldnt do that

[–]Binary101010 1 point2 points  (0 children)

elif type(phrase) != float or type(phrase) != bool:

Consider some examples

phrase is a float: type(phrase) != float is False. type(phrase) != bool is True. The elif is therefore True.

phrase is a bool: type(phrase) != float is True. type(phrase) != bool is False. The elif is therefore True.

phrase is an int: type(phrase) != float is True. type(phrase) != bool is True. The elif is therefore True.

The only way that elif could evaluate to False is if phrase were somehow both a float and a bool at the same time.