Python Forum

Full Version: roll of the dice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everybody

Ive made a program that randomly chose a number of dice from 1 to 6 (as long as we continu the game) then show an image of the dice with the chosen number after playing the dice roll sound using python jupyter but it shows nothing as result

Can anybody help me out ?

here is the program
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

def info():
    print("press q to stop")
    print("press enter to continu")

def show_nbr():
    import random
    valeur= random.randint(1,6)
    return valeur

info()
while True:
    choix = input()
    if choix == 'q':
        break
    from IPython.display import Audio
    from IPython.display import Image
    sound_file = 'dice2.mp3'
    Audio(sound_file,autoplay=True)
    dados='d'+str(show_nbr())+'.jpg'
    print(dados)
    img=mpimg.imread(dados)
    imgplot=plt.imshow(img)
    plt.show()