0% found this document useful (0 votes)
26 views51 pages

Python Project Dice

about a dice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views51 pages

Python Project Dice

about a dice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 51

A

Python Lab Project on


“DICE ROLLING SIMULATOR”
Submitted in the partial fulfillment
of the academic requirements for the degree of

B.Tech in Electronics and Computer Engineering


By
Banoth Pavan (22311A1945)
Kotha Vamshi krishna (22311A1946)
Under the guidance of

Dr.Mohan Dolvan

Department of Electronics & Computer Engineering


SREENIDHI INSTITUTE OF SCIENCE AND TECHNOLOGY
(An Autonomous Institution)
Yamnampet, Ghatkesar Mandal, R.R Dist, Hyderabad - 501301
2023-2024

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.

NAME OF STUDENT ROLL NO.

B. PAVAN 22311A1945

K. VAMSHI KRISHNA 22311A1946

iii
ACKNOWLEDGEMENT

I wish to express immense gratitude to my supervisor, Dr.Mohan Dolvan,


Assistant Professor, ECM Department, for her able guidance and useful
suggestions, which helped me in completing my technical paper writing and
seminar in time. Her valuable suggestions and comments regarding this Project
Work have been very helpful in tackling various obstacles and accomplishing
the major tasks.

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.

Finally, I would like to express my heartful thanks to my beloved parents for


their blessings, friends and classmates for their help and wishes for the
successful completion
iv
Table of Contents:

CONTENTS Page number

1. Introduction 1

2. Algorithim 2

3. Program 3

4. Output 4

5. Explanation 5

6. Steps for executing the program 7

7. Limitations 8

8. Conclusion 9

9. References 10

v
INTRODUCTION

A traditional die is a
f Statement.

cube, with each of its six faces


showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube,
with each of its six faces
showing a different number of
dots
(pips) from 1 to 6. When
thrown or rolled, the die comes
to rest showing on its upper
surface a random integer from
one to six, each value being
equally likely. A variety of
similar devices are also
described as dice; such
specialized dice may have
polyhedral or
irregular shapes and may have
faces marked with symbols
instead of numbers. They may
be used to produce results
other than one through six.
Loaded and crooked dice
are
designed to favor some results
over others for purposes of
cheating or amusement A dice
tray, a tray used to contain
thrown dice, is sometimes used
for gambling or board games,
in particular to allow dice
throws which do not interfere
with other game pieces.
A traditional die is a cube, with each of its six faces showing a different
number of dots(pips) from 1 to 6. When thrown or rolled, the die comes to rest
showing on its uppersurface a random integer from one to six, each value being
equally likely. A variety ofsimilar devices are also described as dice; such specialized
dice may have polyhedral orirregular shapes and may have faces marked with symbols
instead of numbers. They maybe used to produce results other than one through
six. Loaded and crooked dice aredesigned to favor some results over others for
purposes of cheating or amusement A dicetray, a tray used to contain thrown dice, is
sometimes used for gambling or board games,in particular to allow dice throws which
do not interfere with other game pieces.
1

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

return random.randint(min_val, max_val)

def main():

print("Welcome to the Dice Rolling Simulator!")

while True:

input("Press Enter to roll the dice...")

dice_value = roll_dice()

print(f"You rolled: {dice_value}")

roll_again = input("Roll again? (yes/no): ").lower()

if roll_again != 'yes' and roll_again != 'y':


print("Thanks for playing!")

break

if __name__ == "__main__":

main()

OUTPUT :

Welcome to the Dice Rolling Simulator!

Press Enter to roll the dice...

(Here the user presses Enter)

You rolled: 4

Roll again? (yes/no): yes

Press Enter to roll the dice...

(Here the user presses Enter)

You rolled: 2

Roll again? (yes/no): no

Thanks for playing!


4

EXPLANATION

 We import the random module, which provides functions to generate random


numbers. We'll use random.randint() to simulate rolling a dice.

 roll_dice() is a function that simulates rolling a standard 6-sided dice.


 It uses random.randint(min_val, max_val) to generate a random integer between
min_val (which is 1) and max_val (which is 6).
 This function returns the result of the dice roll.
5
 main() is the main function that controls the flow of the program.
 It starts by printing a welcome message.
 It enters a while loop that runs indefinitely (until the user decides to stop).
 Inside the loop:

 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.

STEPS FOR EXECUTING THE PROGRAM

The program is saved in the following process:

1. Open the notepad in the desktop or laptop

2. Do not forget to download the IDE from online which is used as interpreter to
execute the code.

3. Then start writing the code in notepad.

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.

5. Then save the file with .py extension.

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`.

3. **Limited Interaction**: The interaction with the user is minimal—just pressing


Enter to roll the dice and entering `yes` or `no` to continue. For a more interactive
experience, you might want to consider adding more features such as keeping track of
rolls, displaying statistics, or even graphical representation if moving beyond a text-
based interface.

4. **Randomness Quality**: While Python's `random` module is generally adequate


for simple simulations like this, it uses a pseudo-random number generator (PRNG)
which may not be suitable for cryptographic use. In most cases, this is not an issue,
but for applications requiring high-quality randomness, additional steps might be
needed.

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

In conclusion, the dice rolling simulator provided is a basic implementation that


effectively simulates rolling a standard 6-sided dice in a command-line environment.
It serves as a good starting point for understanding basic Python programming
concepts such as functions, loops, conditional statements, and user input handling.
9

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

You might also like