Python dice rolling game, choosing how many dice to roll | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python dice rolling game, choosing how many dice to roll

I'm trying to create a code for this dice rolling game. You have to roll dice until you reach the goal. You roll the dice every turn, which adds to your total so far. You want to hit the goal value exactly, which is 21 by default. The user has to choose how many dice to roll each turn (between 1 and 5). You have to keep rolling dice until you either win by getting 21 or lose by overshooting it. I've come up with this so far, but it is not working properly https://code.sololearn.com/cOk85A6OBcTT/#py How can I make it run correctly? Hint: Make use of while loops to be able to continue as long as needed and try/except to avoid that the program dies after non-integer input. Edit: Fixed some stuff. Jayakrishnain, I did fix that line, but now the issue is that after you do the first dice roll (with the allowed being between 1-5), the second dice roll has no limits. How can I ensure the limits again? The second time you'd be able to chose 10 dice, which is not allowed.

5th Oct 2020, 6:05 PM
Oliver Stephansen
Oliver Stephansen - avatar
4 Answers
+ 2
Why you are saved python code in Web file? How can you/other test it? Save in python code.. This change you need.. Line no 34: dice = input() Edit: did you make this changeOliver Stephansen line 34
5th Oct 2020, 6:17 PM
Jayakrishna 🇮🇳
0
Upload your code in Python mode. Click the + sign in the code section. press "Python" and paste your code. Note that your code request multiple inputes - to do that in Sololearn you need to put all your inputs in the first one splitted by newlines.
5th Oct 2020, 6:32 PM
Nitay Caspi
Nitay Caspi - avatar
0
https://code.sololearn.com/cOk85A6OBcTT/#py Fixed some stuff. Jayakrishnain, I did fix that line, but now the issue is that after you do the first dice roll (with the allowed being between 1-5), the second dice roll has no limits. How can I ensure the limits again? The second time you'd be able to chose 10 dice, which is not allowed.
5th Oct 2020, 7:10 PM
Oliver Stephansen
Oliver Stephansen - avatar
0
Again you can add condition like this in last if : while True : dice = int(input()) if not (dice > 5 or dice < 1): break print ("You can only throw 1 - 5 dice at a time")
5th Oct 2020, 8:40 PM
Jayakrishna 🇮🇳