# Games of chance (Roulette)(int error)

Hey there,

I’m having some issues rapping up this project. How should I deal with attribution error it keeps throwing at me? In the code, .lower() doesn’t work with ints.

I’m trying to allow the player to input either a number or a string ,I.e. (\$4, “Even”) or (\$4, 20).

Thank you !

``````def roulette(wager, guess):
wheel = random.randint(0, 36)
#odd vs. even
red = []
#Logic for odd and even
if guess == int and guess == wheel:
print("{}! Nice playing, you're up \${}.".format(wheel, wager * 35))
return +(wager * 35)
elif guess == int and guess != wheel:
print("{}! Fortune favors the persistent friend".format(wheel))
return -wager
elif guess.lower() == "odd" and wheel % 2 != 0:
print("{} odd! Nice playing, you're up \${}.".format(wheel, wager))
elif guess.lower() == "even" and wheel % 2 == 0:
print("{} even! Nice playing, you're up \${}.".format(wheel, wager))
else:
print("{}! Fortune favors the persistent friend".format(wheel))
``````

Welcome to the forums!

Yes, because what would `lower` mean in the context of working with a number? For a string, it’s obvious that `lower` would change `SHOUTING` to `shouting`… does the same operation make sense on a number? No, hence why it doesn’t exist.

Then you should be examining the input being given to your program to determine which of those situations you’re in, and then proceeding accordingly. One can’t just assume that the input is fine and that your program will be able to handle it “auto-magically”…

Yeah I see your point, I understood why the .lower() wasn’t working, laziness struck hard this morning.

Would I solution to differentiate a string from an integer look something like;

If input == int: ?

1 Like

You can test it yourself to see whether that would work as a solution:

``````my_num = 123

if my_num == int:
print("It's an INT!")
else:
print("Womp womp...")

>>> Womp womp...
``````

This fails because we’re comparing a value (`123`) with a type… which is a bit like saying 10 apples are the same as 10 oranges. Sure, they’re both fruit, but not the same type of fruit…

There are two functions in the built-in function set of Python that could be used to do what you want to do, in conjunction with an appropriate comparison operator (which may or may not be `==`).

I’ll leave you to have a think about which ones.

I’m picking up what you’re putting down!

Thanks for the help!

1 Like

Hey thank you for the help!

As usual for a plebeian, the solution was in plain sight. A simply type() function solved the problem with no issues. A few others could probably work as well but the type() seems to get it done the quickest.

Does modeling the whole game of roulette require some advanced code? Or could it be done with the tools I have available now?

Roulette is basically a random chance game. The complexity would be introduced if you wanted to accommodate other bets than a straight-up bet - like a split or a street, or red/black betting.

That makes sense. Thank you!

There’s rarely a need to check type as in most cases they shouldn’t be mixed in the first place. It’s not like you can read different types as input, when you read input you get a string. If you then decide to convert that string in some way, then you already know the type because you’re the one who made that conversion.

1 Like

Ok I think I understand. Any function input will be some variant of a string? In order to to change the type it has to be done in the function.

Thank you