By SALONI VERMA
Fortunate 6's is a small game designed in Python, It's all about 6's. If your fortunate is with you, it will bring the number 6 as many times as it can and eventually you become the winner.
Fortunate 6's Python Source Code is a game of Fortunate 6's which is programmed in Python Language.
Fortunate 6's is a game which is all about your fortunate. If your fortunate is with you, you'll definitely win the game.
Game Rules-
Consider it like dice, whenever you roll a dice you will get a random number ranging from 0 to 6. But when you got 6 for the first time, you will get another chance to roll the dice. Similarly, you have many chances to roll the dice and at the end, it will calculate how many 6's you got. If you have more than half 6's, then you will win the game. Hence this game is called Fortunate 6's.
In this Python Project, I have used -
1. Random Library (used to insert the random number using function random.randint(1,6))
2. While Loop (used as an infinite loop until and unless the user wants to exit)
3. If Statements (For the conditions of 6s)
4. Print Statements (To print the required information)
5. Several Functions
First a fall, I have defined a function dice_roll() and under this function, I have printed the random number, provided the condition that if the random number is 6, it will print once again as we see in dice. For this, I have used the function recursively.
Then, I have applied an infinite loop which will continue to enter the random numbers until the user wants to exit the game. For this, I have provided an input function to ask the user whether to continue the game or exit the game.
If a user wants to exit the game, the loop will break and it will count the total number of 6's the user got. If count >=half of total outcomes, the user wins the game, otherwise it will print "Better Luck Next Time". For counting, I have used a list, append all the random numbers in it and then used a count function to know the count, and then applied a condition for winning the game.
import random def dice_roll(): n = random.randint(1, 6) d = [] print("Your number is:", n) if n == 6: print("You got 6, therefore you will be having one more chance!!!") return dice_roll() d.append(n) while True: user = input("To roll the dice again enter 'Y' otherwise enter 'N' to exit : ") if user == 'Y': n = random.randint(1, 6) print("Your next number is ", n) elif user=='N': print("Ending the game") break else: print("Invalid Input") d.append(n) a=len(d) c=d.count(6) if c>=a/2: print("You won") else: print("Better Luck next time") print("Welcome to the Game!!") print("Read the game rules:") print("You will get a random number ranging from 1 to 6, but when you got 6, you will get a new chance to roll the dice") print("Then it will ask you whether to roll the dice..after your input it will count how many 6s you got and that decides the winner") a = input("Enter S to start the game : ") if a == "S": dice_roll()
Thanks and Regards,
Saloni
Submitted by SALONI VERMA (saloniverma1906)
Download packets of source code on Coders Packet
Comments