Python program that simulates rolling a 6 sided die and adds up the result of each roll till you roll a 1
If I understand rightly then you can simplify this quite a lot, like this:
import random
print("Well, hello there.")
score = 0
while score < 20:
a = random.randint(1,6)
print("A {} was rolled".format(a))
score += a
if a == 1:
print("Pigged out!")
score = 0
break
print("Turn score is {}".format(score))
python program that Simulates the rolling of two six-sided dice for 1000 times and stores the sum values in a file
Ok, to help with the frequency, you can use a dictionary which you should create before the while
loop:
freq = {}
Then you can use str(result)
as key in the dictionary which you increase if it already exists, and else create the key and set it to 1:
...
result = int(dice_roll) + int(dice_roll1)
key=str(result)
if key in freq:
freq[key] += 1 # increase if already exists
else:
freq[key] = 1 # create new
...
Once you have this dictionary, you should be able to calculate the mean, mode and median.
Program that simulates rolling a dice, and tells you how many times you roll each number
You need to put the line dice=random.randint(1,7)
inside the for loop.
Related Topics
How to Change Python Version in Anaconda Spyder
Get the Row(S) Which Have the Max Value in Groups Using Groupby
How to Increase Dpi With Opencv
Easiest Way to Ignore Blank Lines When Reading a File in Python
Loading and Parsing a Json File With Multiple Json Objects
Move Files Between Two Aws S3 Buckets Using Boto3
Removing Rows and Columns in Python CSV Module
How to Close Child Window in Tkinter
Comparing Two Json Objects Irrespective of the Sequence of Elements in Them
How to Update a Pyspark Dataframe With New Values from Another Dataframe
How to Check All Versions of Python Installed on Osx and Centos
How to Read Numbers from File in Python
Copy All Values in a Column to a New Column in a Pandas Dataframe
How to Extract Hours and Minutes from a Datetime.Datetime Object
How to Close a Tkinter Window by Pressing a Button
Valueerror: Time Data Does Not Match Format When Parsing a Date