Update dice_roller.md

pull/215/head
Ananyagra24 2024-05-19 09:44:37 +05:30 zatwierdzone przez GitHub
rodzic 9220ab33ee
commit 4be728eb47
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -1,8 +1,15 @@
Dice Roller
<br>
The aim of this project is to replicate a dice and generate a random number from the numbers 1 to 6.<br><br>
For this first we will import the random library which will help make random choices.
```
import random
def dice():
dice_no = random.choice([1,2,3,4,5,6])
return "You got " + str(dice_no)
```
The above snippet of code defines a function called "dice( )" which makes the random choice and returns the number that is generated.
```
def roll_dice():
print("Hey Guys, you will now roll a single dice using Python!")
while True:
@ -17,3 +24,6 @@ def roll_dice():
print("Thanks for rolling the dice.")
roll_dice()
```
The above code defines a function called "roll_dice( )" which interacts with the user.<br>
It prompts the user to give an input and if the input is k,the code proceeds further to generate a random number or gives the message of invalid input and asks the user to try again.<br>
After the dice has been rolled once, the function asks the user whether they want a reroll in the form of a yes or no question.The dice is rolled again if the user gives 'yes' as an answer and exits the code if the user replies with anything other than yes.