I know I am a bit lazy on the except handling part of python programing, but perhaps I should not teach that to others: But worse, still, if a user is crafty, they'll recognise this problem rouletre throw a system command at it - and it will execute. Please take a moment and Register today!
You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser. Discussion in ' Division by Zero ' started by AndyMar 10, Mar 10, 1.
I'm relatively new at programming, and Python is my first language so please take that into consideration before you read on. Right, I am trying to create a Roulette type of game in Python. It asks for a number between 0 and 36, or it asks for you to place a bet on it being an odd or even number.
This is the bet the user is making. It then generates a random number between 0 and What I need to do, is for the program to check if the bet is an integer or not, and if it is, see if it matches the random number that was made. If it does, you have won and it should say "Big Winner". If it isn't right, then it should display something like "Sorry, you have won nothing". BUT, if the user inputted "odd" as their bet, it should check to see if it is an odd or even number. If it's odd, it should give them the message "Little Win".
So if they guess if the random number generate is odd or even correctly, they win. However, I'm stuck on how to go about doing this. As I have said, I am quite new to programming, and have only been able to do the following code: Should I create another function or something? Mar 10, 2. I think you need to clarify the requirements of this program as the information you're providing does not exactly match with the code you've attempted to write.
Mar 10, 3. Yeah, I got a few bits wrong in the post, sorted now. Mar 11, 4. Does your program expect a number between 1 and 36 or a number between 0 and 36 [both non-inclusive]? It's all very confusing and something that will result in unexpected usage of your program If a user enters a number, say, 9, it'll be eval'ed and converted to an integer. If a user enters a string, it won't be a string unless they quote the string. But worse, still, if a user is crafty, they'll recognise this problem and throw a system command at it - and it will execute.
Despite this being a small program, I ask that you get into the habit of commenting things Whenever asking a user to enter something within a range, you're going to online gambling advertisements to check if their input is within the range you're looking for.
If this isn't the case, re-prompt them to input a number after having displayed an error. What if I enter the number 40? Mispelt odd or even? I noticed you've used multiple if statements when this really isn't necessary. Instead, you should be employing the use of elifs and get into the habit of using proper decision structures. Otherwise, things look alright and I'm glad that you're learning from us. Mar 11, 5. Mar 11, 6.
Thanks guys for the help, it's very appreciated I have changed the two "if" statements to "elif", and it's funny that you should mention about commenting, as just after I posted it I put some comments on it And yeah, I think my teacher was unclear about the whole business. After school today I am going to fix it up and make it cleaner, and possible add some other stuff. Mar 11, 7. Well I have quickly made some adjustments, including adding an error if anything incorrect is added. Instead I have just made it exit the program.
Anyone know how to do this? If the digit is greater than 35, it will print an error and exit the program print "Sorry, you have entered an incorrect value" sys. If the digit is less than 0, it will print an error and exit the program print "Sorry, you have entered an incorrect value" sys.
If a string other than "odd" or "even" is entered, it will exit the program print "Sorry, you have entered an incorrect value. Mar 12, 8. If you acknowledge the problem, why don't python just fix it? The logic to solve this problem is simple: Determine what kind of python is required by your program in this case, the case of the user's input doesn't matter, only the spelling does 2. Based on this, develop a means of formatting the user's input to your liking i.
For this program we can just lowercase all the user's input, like so: So, let's strip all whitespace from their input using strip: Strip all whitespaces to ensure the user doesn't leave any in their input if bet. If you can place yourself in the user's shoes, you'll find it is quite easy to do so. A little note on your instructions: What does it mean to "choose" 'odd' or 'even'? For most people, they'd try clicking on them.
If the digit is greater than 35, it will print an error and exit the program print "Sorry, please enter a number less than If the digit is less than free video gambling, it will print an error and exit the program python "Sorry, please enter a number greater than 0.
To answer your question, read through this thread on starting to pick up turingas I have outlined the logic you should follow in it. If you don't understand anything, or would like it to be translated to Python or whatever, feel free to ask. Mar 13, 9. Another good note would be online gambling bonus forum take into thought would be the string "odd number" as input.
All the above programs would falsify that as input even though it is correct. So you need a way goldmine roulette system check only if the string contains "odd" not if it equals odd. You must log in or sign up to reply here. Share This Page Tweet. Your name or email address: Welcome to our site!
Please take new york city gambling sign moment and Register today!Instantly share code, notes, and snippets. Star 0 · Fork 0 Roulette Python. Raw. betcasino.top #!/usr/bin/env python. rollcount = 0. print("Welcome to Roulette!"). Python roulette game. Contribute to roulette development by creating an account on GitHub. developers working together to host and review code, manage projects, and build software together. Simple Roulette game written in Python. Instantly share code, notes, and snippets. Python module to output the color of a roulette pocket based on an input number 0- Name: Roulette Wheel Colors.