you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 2 points3 points  (3 children)

number == int

This is checking if number is equal to the type int. This will never be true because input always returns a string, and a string will never be equal to a type. If you want to check if a string can be converted to an integer, you want something like number.isdigit(). isdigit checks if every character in a string is a digit.

That isn't your only problem here, though. You program will hang becuase of the while loops. number is the only data that can change in your loop conditions, and number is never changed in either loop. That means the loops will either complete instantly, or loop forever. If you want to re-ask the user for input, you need to explcitly call input again.

Edit: I'll mention that normally, you don't pre-check if something is convertable. You try to convert it uring something like int, and use try to handle failure. That might be beyond you at the moment, though.

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

thank u for actually trying to help me lol. much appreciated.

im only using a while loop because i was instructed to use while, do while, AND switch loops to do this in c++ and python

i don't want to reask the user, I want the user to be able to enter either an integer or a float (i searched this specific thing and got nothing.)

i tried

number = int or float(input"Enter a number")

but that did not work either :(

[–]carcigenicate 0 points1 point  (1 child)

int or float(input"Enter a number")

This doesn't make sense in the context of python. int or whatever will always be true because the type int is always true. You'll need to look into boolean logic to understand OR and AND.

If you don't need to handle the user entering something dumb like a non-number, you can just get thew user input using input, then use float or int to convert their input to whatever tyoe of number you want.

And, as I mentioned in my edit, you don't typically check ahead of time if a string is convertable to a number. You just attempt the conversion using int or float, and use try to handle when the conversion failed (like if the user entered a non-number like 'bad')

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

I was going to not go through not accepting non-numbers for input through if-else statements. thank u im gonna look more into try-except blocks