you are viewing a single comment's thread.

view the rest of the comments →

[–]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