Dice

--Originally published at PYTHON 3

A month without posting any new blogs because of different reasons i’m back with some mini projects I’ve been developing since the beginning of the partial, this is the first one which is a program that rolls a dice, a very simple code.

To do this program we need to import the random library, next we do our object “dice” as a list that includes the 6 numbers

dice = [1,2,3,4,5,6]

we print a welcome text and make an input to press enter and start a while loop, and while the loop is true it will run the next code:

while True:

pass #it will run the instructions in order

print(“The number is: ” , random.choice(dice)) #random.choice() selects a random object from a list
print(‘\n’)
print(“Want to roll again?”+’\n’)
print(“(1) Yes.”+’\n’)
print(“(2) No.”+’\n’)

Now the program has given a number from 1 to 6 and is asking us if we want to run it again

answer = int(input(‘\n’))

if answer == 2:
break

elif answer != 1:
print(“Sorry but that’s not an option… Try again”+’\n’)

screenshot-from-2016-10-15-17-09-14

screenshot-from-2016-10-15-17-08-38

Now i can play monopoly with my own virtual dice

monopoly