lundi 22 octobre 2018

Python 3 ball drop histogram

I have to make a code that drop balls each of which will bounce randomly and land in a slot. There will be 21 slots (numbered from -10 to 10). Each ball will be dropped over the middle slot (number 0) and "bounce" 10 times and turn it into a histogram that looks like this:

how many balls? 20
-10 : 
-8  : o
-6  : oo
-4  : oo
-2  : oooo
0   : oooo
2   : oooo
4   : oo
6   : 
8   : o
10  : 

The code i have so far is:

import random

def number():
    import random
    for i in range(0, 21):
      random.randint
def balls ():
    range(1, 21)
    bounce(2*random.randint(0, 1) - 1)



# builds and returns one line of the output histogram
# "number" identifies the slot and "balls" is how many o to place
def build_line(number, balls) :
    line = str(0) + '\t: '   # slot number and tab character
    for i in range(1, 3) :       # build a line of o characters
        line += 'o'               # add another o to the line
    return line

def display(count):
    print (build_line(i - 10, count[i]))

def main():
    import random
    val = input('balls?')
    list = random.randint(1, 9)
    output = number()
    retval = build_line(list, output)
    display(range(0,20))
    print (retval)

main()

and i don't know where to go from here. Does anybody know how oi can fix it?




Aucun commentaire:

Enregistrer un commentaire