Jump to content

[Python 3] Help with displaying results from dice simulator(Solved)

Remesy

Hi, so I need help with displaying results from the dice simulator I made for a project and I don't know where to start. (The giant blank spot is where I plan to put the code to display the results) 

Edit1: nvm got it just had to use loop for it.

Edit2:Deleted the code.

Edit3: This time I got it to work but the program gets stuck at the loop for displaying the result if it was set to roll more than 8 times and the problem seems to be the loop to display the results. Need help to see why that is happening.

Edit4:Solved, the issue it was because of having a loop inside a loop.

Here's the code that is causing the issue.

Rollagain = True#Counter for how many times the program was run.Run = 1#importing module to use randomimport random#Loop statement to re-run the program if Rollagain is Truewhile Rollagain:#Displays counterprint('Simulation: ', Run)#Asking how many sides do they want on their dicesides = int(input("How many sides do you want on the dice? "))#list to use to store how many times a number has been rolledamountofsides = [0] * sides#Asking how many times do they want to rollamountofrolls = int(input('How many rolls do you want to do? '))#A counter to count how many times the program already rolled so it knows when to stoprolling = 0#Loop to keep rolling until it has reached the desired amount the person wanted to rollwhile rolling < amountofrolls:#Adding 1 to the counter of how many times it has been rolledrolling = rolling + 1#Gets a random number from 1 to however many sides the person desiredfacevalue = random.randrange(1, sides + 1)#Stores the number into the listamountofsides[facevalue-1] += 1#Conter to display the dot numberdicenumber = 1#Used to pull the numbers from amountofsidespullfromlist = 0#Displays the countentsprint(' Rolled Freq. Percentage Rolled')percentagetotal = []#loop to keep displaying results from amountofsides until the endwhile pullfromlist <= amountofrolls:#loop to display all sides of the dicewhile dicenumber <= sides:#Calulation to display percentagepercentagel = float(100 * amountofsides[pullfromlist]/amountofrolls)#rounding the calulationrpercentagel = round(percentagel, 2)#displaying the resultsprint('Dot ', dicenumber, ' : ', amountofsides[pullfromlist], ' ', rpercentagel, "%")#Add 1 to the dicenumber counterpercentagetotal.append(rpercentagel)dicenumber += 1#Add 1 to the pullfromlist counterpullfromlist += 1#Displaying resultsprint('------------------------------------------------')print('Total: ', sum(amountofsides), ' ', round(float(sum(percentagetotal)), 1), '%')#loop statements asking if they want to do the simulation againvalidinput = Falsewhile not validinput:response = input("\n\nDo you want to continue 'yes' or 'no'? ").lower()if response == "yes":validinput = TrueRollagain = Trueelif response == "no":validinput = TrueRollagain = Falseelse:print("You have enter an invalid term.")validinput = False#Adds 1 to the run counter from line 9Run += 1
while pullfromlist <= amountofrolls:#loop to display all sides of the dicewhile dicenumber <= sides:#Calulation to display percentagepercentagel = float(100 * amountofsides[pullfromlist]/amountofrolls)#rounding the calulationrpercentagel = round(percentagel, 2)#displaying the resultsprint('Dot ', dicenumber, ' : ', amountofsides[pullfromlist], ' ', rpercentagel, "%")#Add 1 to the dicenumber counterpercentagetotal.append(rpercentagel)dicenumber += 1#Add 1 to the pullfromlist counterpullfromlist += 1
#loop to display all sides of the dicewhile dicenumber <= sides:#Calulation to display percentagepercentagel = float(100 * amountofsides[pullfromlist]/amountofrolls)#rounding the calulationrpercentagel = round(percentagel, 2)#displaying the resultsprint('Dot ', dicenumber, ' : ', amountofsides[pullfromlist], ' ', rpercentagel, "%")#Add 1 to the dicenumber counterpercentagetotal.append(rpercentagel)dicenumber += 1#Add 1 to the pullfromlist counterpullfromlist += 1
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×