Python Project Dice
Python Project Dice
Dr.Mohan Dolvan
i
Department of Electronics and Computer Engineering
Sreenidhi Institute of Science and Technology
CERTIFICATE
This is to certify that the Python Lab Project entitled “Dice Rolling Simulator”
submitted by B. Pavan, K. Vamshi Krishna bearing Roll No.
22311A1945,22311A1946 in the partial fulfillment for the award of Bachelor of
Technology Degree in Electronics and Computer Engineering from Sreenidhi
Institute of Science & Technology, Ghatkesar, Hyderabad, is a record of
bonafide work done by them during the academic year 2023-2024 under our
guidance and evaluation.
Dr. D. Mohan
HOD
ECM
ii
DECLARATION
This is to certify that the Python Project titled “Dice Rolling Simulator” is a
record work done by us in the Department of Electronics and Computer
Engineering (ECM), Sreenidhi Institute of Science and Technology, Ghatkesar,
Hyderabad.
The report is based on the project work done entirely by our team and not
copied from any other source.
B. PAVAN 22311A1945
iii
ACKNOWLEDGEMENT
I take immense pleasure in thanking HOD Dr. D.Mohan, Principal Dr. Ch.
Shiva Reddy, all faculty members of ECM Department for having permitted
me to carry out this project work.
1. Introduction 1
2. Algorithim 2
3. Program 3
4. Output 4
5. Explanation 5
7. Limitations 8
8. Conclusion 9
9. References 10
v
INTRODUCTION
A traditional die is a
f Statement.
ALGORITHIM
Display a welcoming message to the user, indicating that they are entering a
dice rolling simulator.
Enter a loop that continues until the user decides to stop rolling.
Ask the user to press Enter to roll the dice. This interaction simulates the action
of rolling the dice.
Use a random number generator to simulate the result of rolling a standard 6-
sided dice. This can be achieved with Python's random.randint() function,
where the minimum value (min_val) is 1 and the maximum value (max_val) is
6.
Print out the result of the dice roll to the user. For example, display "You
rolled: X" where X is the random number generated.
Ask the user if they want to roll the dice again. Allow input to be case-
insensitive (accepting "yes" or "no" in any case).
If the user wants to roll again (input is "yes" or "y"), repeat steps 3-6.
If the user does not want to roll again (input is "no" or "n"), exit the loop.
Display a closing message to thank the user for playing the simulator.
2
PROGRAM
import random
def roll_dice():
min_val = 1
max_val = 6
def main():
while True:
dice_value = roll_dice()
break
if __name__ == "__main__":
main()
OUTPUT :
You rolled: 4
You rolled: 2
EXPLANATION
It waits for the user to press Enter to roll the dice using input("Press Enter to
roll the dice..."). The result of this input() function call is ignored because we
only care about waiting for the Enter key press.
It calls roll_dice() to get a random dice roll result and stores it in dice_value.
It prints out the result of the dice roll using print(f"You rolled:
{dice_value}").
It prompts the user whether they want to roll again by using input("Roll again?
(yes/no): ").lower(). .lower() is used to convert the user's input to lowercase to
handle both "yes" and "YES" inputs.
If the user enters anything other than 'yes' or 'y', the loop breaks, printing "Thanks for
playing!" and ending the program.
This conditional statement checks whether the script is being run directly (as opposed to
being imported as a module).
If __name__ is "__main__", it means the script is being run directly, so it calls main() to
start the program.
2. Do not forget to download the IDE from online which is used as interpreter to
execute the code.
4. NOTE: Write the program very carefully try to write it without errors and do
follow the steps of program that are required in the python.
6. Open in IDE file and execute in the program then you see the errors and work
on it.
7
LIMITATIONS
While the dice rolling simulator code provided is functional for basic use, there are a
few limitations and considerations:
1. **Single Dice Type**: The simulator is designed specifically for a standard 6-sided
dice (`min_val = 1` and `max_val = 6`). If you want to simulate different types of dice
(e.g., 4-sided, 10-sided), you would need to modify the `roll_dice()` function to accept
parameters for minimum and maximum values.
2. **Input Handling**: The program expects specific user inputs (`yes` or `no` to
continue rolling). It doesn't handle unexpected inputs well, which could cause errors
or unexpected behavior if the user inputs something other than `yes` or `no`.
5. **Error Handling**: The code lacks robust error handling. For instance, it assumes
that the user will always press Enter when prompted to roll the dice and will always
provide valid input when asked whether to roll again. Adding error handling could
improve the user experience by gracefully handling unexpected inputs or errors.
Addressing these limitations would enhance the functionality, robustness, and user
experience of the dice rolling simulator, making it more versatile and suitable for broader
applications or gaming scenarios.
CONCLUSION
REFERENCES
1. https://www.studocu.com/in/document/vishweshraiya-college-of-education/computer-
science-engineering/dice-rolling-simulator-report/69072808?sid=01720340463&shared=n
2. https://www.scribd.com/document/542241729/Dice-Rolling-Simulator-Jagrit-Sahni
3. https://www.tutorialspoint.com/dice-rolling-simulator-using-python-random
- :~:text=Dice%20Rolling%20Simulator%20is%20a,languages%20for%20making%20dice
%20simulators
10