PDA

View Full Version : Coding Coding Help (DICE GAME) Python 3.2



Gizmogidget
2016-04-02, 02:23 PM
I have been having problems with my dice game code that I copied from a practice example. It returns syntax/keyboard errors. I have never had the practice code not work. My teacher has been spectacularly unhelpful, and I can't seem to get a hold of him.
The code is as follows
from dice import Dice

player_dice = Dice(10)
computer_dice = Dice(10)

while (player_dice.count_dice() > 0
and computer_dice.count_dice() > 0):
print("Your dice:\t\t" + str(player_dice.count_dice()))
print("Computer's dice:|t" + str(computer_dice.count_dice()))
print("Press the ENTER key to roll!")
input()
player_dice.roll_dice()
computer_dice.roll_dice()
player_total = player_dice.add_up_total()
computer_total = computer_dice.add_up_total()
print("You rolled " + player_dice.dice_to_string() +
", for a total of" + str(player_total) = ".")
print("The computer rolled " + computer_dice.dice_to_string() +
", for a total of " + str(computer_total) + ".")

Thanks for all the help I have gotten in the past

NichG
2016-04-02, 09:25 PM
Python code can end up having 'invisible' errors in code that looks like it should be perfectly fine because python cares a lot about consistent indentation at the beginnings of lines. So for example, your while loop is invalid in python because the code block below it isn't indented. There's also some particular things about where you can break things when extending one line of code over multiple lines in the file, so you might want to try putting all your multi-line things on a single line to see if that fixes it.

Jasdoif
2016-04-02, 11:00 PM
print("You rolled " + player_dice.dice_to_string() +
", for a total of" + str(player_total) = ".")That equal sign at the end should be a plus sign.

Gizmogidget
2016-04-03, 01:16 PM
Thank you for all the help, on a side note this is my last year of I.T at my high school. I would like to keep learning any options you'd recommend?