___  ___    _ _    _  _ _____   _____
 / __|/ _ \  | | |  | || |_ _\ \ / / __|
| (_ | (_) | |_  _| | __ || | \ V /| _|
 \___|\___/    |_|  |_||_|___| \_/ |___|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Tutorial: Create a dice game with python.

BY: @guliko | CREATED: May 3, 2020, 5:01 p.m. | VOTES: 6 | PAYOUT: $1.04 | [ VOTE ]

> I want to warn you that I am not an expert in programming, I discover and I share with you in order to make you take full advantage of my programs and progress together.

Welcome to this tutorial: How to create a dice game on python. It is very simple!

[IMAGE: https://images.hive.blog/DQmbftxD3LEn3cKmZ6VpVSfZhTuuYPMiiayzh3iADPtvA94/d%C3%A9butant%20post%20img.jpg]

Presentation:

The game has 6 possible outcomes (like a 6-sided die). You must choose a number between 1 and 6 then a number will be generated randomly. If you have the same then you win otherwise you lose.

If I chose the number 2 and it generates the number 5 I lost, and if I chose the number 2 and it generates the number 2, I won.

[IMAGE: https://images.hive.blog/DQmPVoRE8eu7Y3EvpW8c6CafaHgko8ppugLow38643ZBebV/won.PNG]

The program:

[IMAGE: https://images.hive.blog/DQmfPwqh9CPssZdC4cmrBv3XC18bYxNrtN9krhwb8heRnZX/Capture.PNG]

from random import

print("Welcome to the dice game !")
print("Rules: Choose a number between 1 and 6, then press your 'Enter' key.")
print("A number will generate randomly and if you have the same as the generated number, you will win.")
number_choose = int(input("Chooser a number between 1 and 6."))
generate = randint(1, 6)
print("The number generated is: {}.".format(generate))

if number_choose is generate:
print("You won !")
else:
print("You lost!")

Explanations:

"from random import" : We import into "random" library: randint. Randint is used to generate a random number.

print("...") : "Print ()" is used to send a message to the console, we use it to give the result, to say the rules ...

"number_choose = int(input("Chooser a number between 1 and 6."))" : We will create the variable "number_choose" which will be equal to the response of "Chooser a number between 1 and 6.".

"generate = randint(1, 6)" : We will create the variable "generate" which will recover the number generated between 1 and 6 thanks to the randint function.

"print("The number generated is: {}.".format(generate))" : We announce the number that has been generated. ".format (generate)" will be used to replace the {} to put the value of the variable "generate" and therefore say the number selected.

"if number_choose is generate:
print("You won !")
else:
print("You lost!")"
: If the number chosen ("number choose") is the same as the number generated ("generate"), then say "You won!" or otherwise "You lost!".

> The article is finished, thank you for taking the time to read my post and good luck to you <3
If you have any problems or questions, tell me!

[IMAGE: https://images.hive.blog/DQmcXzzgkJbFMju7baDtmwtbZ971XjN4UdVd2BV9KX2sbLX/Capture.PNG]

by @guliko.

TAGS: [ #GEMS ] [ #dev ] [ #en ] [ #python ] [ #dice ]

Replies

@gitplait | May 4, 2020, 12:51 p.m. | Votes: 1 | [ VOTE ]

This is a nice tutorial. The GitPlait community reward tutorials like this. If you wish, you could join our community.

https://hive.blog/trending/hive-103590

Cheers!

@guliko | May 4, 2020, 2:49 p.m. | Votes: 0 | [ VOTE ]

Thanks, I'm coming to see your community right away ;-)

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>