Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:23:24+00:00 2026-06-13T12:23:24+00:00

I made this dice game in python, but am getting a syntax error with

  • 0

I made this dice game in python, but am getting a syntax error with my inputdice function. Below is the dice game in its entirety. When run, the game should go through 10 rounds and stop after round 10 or when the user runs out of money. Any suggestions?

from random import *

def dice1():
    print("+-----+")
    print("|     |")
    print("|  *  |")
    print("|     |")
    print("+-----+")

def dice2():
    print("+-----+")
    print("|*    |")
    print("|     |")
    print("|    *|")
    print("+-----+")

def dice3():
    print("+-----+")
    print("|*    |")
    print("|  *  |")
    print("|    *|")
    print("+-----+")

def dice4():
    print("+-----+")
    print("| * * |")
    print("|     |")
    print("| * * |")
    print("+-----+")

def dice5():
    print("+-----+")
    print("|*   *|")
    print("|  *  |")
    print("|*   *|")
    print("+-----+")

def dice6():
    print("+-----+")
    print("|*   *|")
    print("|*   *|")
    print("|*   *|")
    print("+-----+")

def drawdice(d):
    if d==1:
        dice1()
    elif d==2:
        dice2()
    elif d==3:
        dice3()
    elif d==4:
        dice4()
    elif d==5:
        dice5()
    elif d==6:
        dice6()
    print()

def inputdie():
    dice=input(eval("Enter the number you want to bet on --> "))
    while dice<1 or dice>6:
        print("Sorry, that is not a good number.")
        dice=input(eval("Try again. Enter the number you want to bet on --> "))
    return dice

def inputbet(s):
    bet=input(eval("What is your bet?"))
    while bet>s or bet<=0:
        if bet>s:
            print("Sorry, you can't bet more than you have")
            bet=input(eval("What is your bet?"))
        elif bet<=0:
            print("Sorry, you can't bet 0 or less than 0")
            bet=input(eval("What is your bet?"))
    return bet

def countmatches(numbet,r1,r2,r3):
    n=0
    if numbet==r1:
        n+=1
    if numbet==r2:
        n+=1
    if number==r3:
        n+=1
    return n


def payoff(c,betam):
    payoff=0
    if c==1:
        print("a match")
        payoff=betam
    elif c==2:
        print("a double match!")
        payoff=betam*5
    elif c==3:
        print("a triple match!")
        payoff=betam*10
    else:
        payoff=betam*(-1)
    return payoff


def main():
    dollars=1000
    rounds=1
    roll=0
    single=0
    double=0
    triple=0
    misses=0
    flag=True
    print("Play the game of Three Dice!!")
    print("You have", dollars, "dollars to bet with.")
    while dollars>0 and rounds<11 and flag==True:
        print("Round", rounds)
        dicebet=inputdie()
        stake=inputbet(dollars)
        for roll in randrange(1,7):
            roll1=roll
        for roll in randrange(1,7):
            roll2=roll
        for roll in randrange(1,7):
            roll3=roll
        drawdice(roll1)
        drawdice(roll2)
        drawdice(roll3)
        matches=countmatches(dicebet,roll1,roll2,roll3)
        dollarswon=payoff(matches,stake)
        if matches==1:
            single+=1
        elif matches==2:
            double+=1
        elif matches==3:
            triple+=1
        elif matches==0:
            misses+=1
        if dollarswon>0:
            print("You got a match!")
            print("You won $", dollarswon, sep='')
            dollars=dollars+dollarswon
            print("Your stake is $", dollars, sep='')
        else:
            print("You lost your bet! $", stake, sep='')
            dollars=dollarswon+dollars
        rounds+=1
    if rounds==10:
        print("*******Singles", single, "Doubles", double, "Triples", triple, "Misses", misses)
        answer=input("Want to play some more? (y or n)")
        if answer=="y":
            main()
        else:
            print("Have a good day")

main()

Any help is appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:23:25+00:00Added an answer on June 13, 2026 at 12:23 pm

    The proximate error is that eval() expects an expression that is valid python syntax;
    "Enter the number you want to bet on -->" or any of the other strings in this program are not valid python expressions, hence the syntax error produced at run time.

    The broader problem with the program, is that eval() is not necessary and should be avoided.

    A rule of thumb, particularly for beginners, is that “eval() is evil” and should “never” be used.
    Note that “never” is in quotes, to hint at the fact that there are indeed a [very] few use cases where eval() can be very useful.
    The reason why eval() is such a “dangerous ally” is that it introduces [typically user-provided] arbitrary python expressions at run-time, and there’s a good chance that such expression could have an invalid syntax (no big deal) or worse, could include rather harmful or possibly even malicious code, which when invoked would perform all sorts of bad things on the host…

    This said, you do not need eval() at all to process the input obtained from the input() method.
    I think that you may have meant to use patterns like:
    myVar = eval(input("Enter some value for myVar variable"))
    (i.e. with the eval and input in the reverse order)
    Actually this would still not work for eval() requires a string argument, and hence you would have needed
    myVar = eval(str(input("Enter some value for myVar variable")))
    but as said eval() is not warranted here.

    Another guess is that you used eval() because you expected the return from input() to be of type string, and that eval() would turn this into a integer for use with the program logic…
    raw_input() is the method returning a string, and it is plausibly the one that you should use to avoid getting run-time errors when the user types in text without quotes and other invalid values. A common idiom to get the user to input integer values, is something like

    int_in = None
    while int_in == None:
       str_in = raw_input('some text telling which data is expected')
       try:
           int_in = int(str_in)
       except ValueError:
           # optional output of some message to user
           int_in = None
    

    Typically we put this kind of logic in a method for easy reuse.

    Hope this helps. You seem to be doing practical things with Python: no better way to learn than to code – along with the occasional review of the documentation and reading of a related book. A plug for good book: Python Cookbook by Alex Martelli

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this function to verify a user's twitter credentials. Its running on two
I made this code with jquery autocomplete its just like facebook search function now
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
I made this little function from code snippets around the net. It does what
I made this simple function to filter the data. I add the symbols that
Made this custom alert box: <script type="text/javascript"> $(function () { var $alert = $('#alert');
I made this simple function (remove all $elem from $array): function remall($array, $elem) {
I made this little function: public String getDay() { String day = (String)android.text.format.DateFormat.format(E, new
I made this question over at the Openfire groups, but it seems to be
I made this code to resize images with two factors. It works, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.