My code:
I made some code that prints 100 random values from a range 1-8, and if the number is from 1-5 it prints and x next to it and if it 6-8 it prints a y. I'm wondering how I can print the number of times an x is printed and a y is printed.
I'm also wondering why i had to make a conditional statement for every individual value i wanted to print x for, instead of just writing this [which didn't work properly]
asked Apr 10, 2016 at 0:01
1
Put x and y in a dictionary and increment every time in the loop, the frequency they occur:
import random
numbers = {'x': 0, 'y': 0}
def randomnumbers[]:
for x in range[100]:
n = random.randint[1, 8]
if 1