From 977725281c1aea006778ea9d720f8a2f69a11c5b Mon Sep 17 00:00:00 2001 From: Satyarth Pandey Date: Wed, 28 May 2025 00:34:11 +0530 Subject: [PATCH] Fix typo, add score feature, and input validation warning in dice game Corrected a typo in the game text to improve clarity. Added a feature that keeps track of the total score based on dice rolls, enhancing gameplay. Implemented input validation to display a warning message whenever the user enters a character other than 'y' or 'n', making the game more user-friendly and preventing invalid inputs. --- Dice-Simulator/dice.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Dice-Simulator/dice.py b/Dice-Simulator/dice.py index 798e30dd..447c54a7 100644 --- a/Dice-Simulator/dice.py +++ b/Dice-Simulator/dice.py @@ -46,17 +46,23 @@ def roll_dice(): print("| |") print("| 0 0 0 |") print("-----------") + return number - -print(" Dics Simulator ") +print(" Dice Simulator ") +score=0 x = 'y' while x.lower() == "y": - roll_dice() # function call + + rolled_number=roll_dice() #function called + score+=rolled_number + print("Your Score: ",score) choice = input("Do you want to play again (y/n): ") # choice from user if choice.lower() == "n": + print('Your final score: ',score) exit(0) - - - - + elif choice.lower()=='y': + continue + else: + print("Invalid Input! Exiting program.") + exit(0)