Python Pbl
Python Pbl
A PBL Report
On
BACHELOR OF TECHNOLOGY
IN
Submitted By
CH.RAHUL-218R1A66E5
D.SRI VIDYA-218R1A66F1
M.NANDHINI-218R1A66G8
P.ALEKYA-218R1A66H6
CERTIFICATE
CH.RAHUL-218R1A66E5
D.SRI VIDYA-218R1A66F1
M.NANDHINI-218R1A66G8
P.ALEKYA-218R1A66H6
in partial fulfillment of the requirement for the award of the degree of BACHELOR OF TECHNOLOGY in COMPUTER SCIENCE AND
ENGINEERING(AI & ML) from CMR Engineering College,under our guidance and supervision.
The results presented in this project have been verified and are found to be satisfactory. The results embodied in this project have not been submitted to any other
university for the award of any other degree or diploma.
________________ _______________________
DECLARATION
This is to certify that the work reported in the present project entitled " DICE ROLLING SIMULATOR PYTHON GAME " is a record of bonafide work
done by me in the Department of Computer Science and Engineering(AI & ML), CMR Engineering College. The reports are based on the project work done entir
ely by me and not copied from any other source. I submit my project for further development by any interested students who share similar interests to improve th
e project in the future.
The results embodied in this project report have not been submitted to any other University or Institute for the award of any degree or diploma to the best of our k
nowledge and belief.
CH.RAHUL-218R1A66E5
D.SRI VIDYA-218R1A66F1
M.NANDHINI-218R1A66G8
P.ALEKYA-218R1A66H6
Python is a high-level, interpreted, interactive, and object-oriented scripting language. Python was designed to be highly readable which uses English keywords frequently whereas other la
nguages use punctuation and it has fewer syntactical constructions than other languages.
It is used in :
1. Software Development
2. Web Development
3. System Scripting
4. Mathematics
Its large and robust standard library makes Python score over other programming languages. The standard library allows you to choose from a wide range of modules according to your
precise needs. Each module further enables you to add functionality to the Python application without writing additional code. For instance, while writing a web application in Python, you
can use specific modules to implement web services, perform string operations, manage operating system interface or work with internet protocols. You can even gather information about
As an open source programming language, Python helps you to curtail software development cost significantly. You can even use several open source Python frameworks, libraries and dev
elopment tools to curtail development time without increasing development cost. You even have option to choose from a wide range of open source Python frameworks and development to
ols according to your precise needs. For instance, you can simplify and speedup web application development by using robust Python web frameworks like Django, Flask, Pyramid, Bottle
and Cherrypy. Likewise, you can accelerate desktop GUI application development using Python GUI frameworks and toolkits like PyQT, PyJs, PyGUI, Kivy, PyGTK.
Python is commonly used for developing websites and software, task automation, data analysis, and data visualization. Since it’s relatively easy to learn, Python has been adopted by many
non-programmers such as accountants and scientists, for a variety of everyday tasks, like organizing finances.
“Writing programs is a very creative and rewarding activity,” says University of Michigan and Coursera instructor Charles R Severance in his book Python for Everybody. “You can write
programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem.”
Contents:
1
.Introduction
2. Problem Statement
3.Implementation
4.Source code
4.1. Code
4.2. Screenshots
5.Conclusion
1.Introduction:
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 show-
ing 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 special-
ized 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 con-
tain thrown dice, is sometimes used for gambling or board games, in particular to allow dice throws which do not interfere with other game pieces.
Snake and Ladders, Ludo and Checkers, are the most favorite games of all time. But, it feels terrible when you drop the plan of playing just because you couldn’t
find the dice. So, here is a fascinating option to give you a chance to make something cool. Let’s build a Dice Rolling Simulator with basic knowledge of Py-
thon.
2.
Problem Statement:
Python program to dice. It’s a simple cube with numbers from 1 to 6 written on its face. But what is simulation? It is
making a computer model. Thus, a dice simulator is a simple computer model that can roll a dice for us.
Tkinter:
Python offers various packages to design the GUI, i.e. the Graphical User Interface. Tkinter is the most common, fast, and
easy to use Python package used to build Graphical User Interface applications. It provides a powerful Object-Oriented Inter-
face and is easy to use. Also, you develop an application; you can use it on any platform, which reduces the need of amend-
ments required to use an app on Windows, Mac, or Linux.
3
. Implementation
in our UI.
Random: Imported to generate random numbers.
CODE:
import tkinter
from PIL import Image, ImageTk
import random
3.2 Create the GUI:
In this step, we will build the main window of our application, where the buttons, labels, and images will reside. We also give it a title by title() function.
CODE:
root = tkinter.Tk()
root.geometry('600x600')
root.title('ProjectGurukul Roll Dice')
#label to print result
label = tkinter.Label(root, text='', font=('Helvetica', 260))
#label to introduce
label2 = tkinter.Label(root, text='Welcome to ProjectGurukul Dice roll. Click to roll dice ', font=('Helvetica',10))
label2.place(x=150,y=400)
EXPLANATION:
The above code sets the title of the application window as ‘DataFlair Roll the Dice’. Running the above code will generate a blank window of dice rolling simu-
lator python project with the title on it.
Now, just think, what we need to roll a die? Just our hands!
The below code will add a label giving a heading to our dice simulator. Also, we will add an image area, which will display the image
chosen by random numbers.
CODE:
EXPLANATION:
Here, we use pack() to arrange our widgets in row and column form. The ‘BlankLine’ label is to skip a line, whereas we use ‘HeadingLabel’ label to give a heading.
root – the name by which we refer to the main window of the application
text – text to be displayed in the HeadingLabel
fg– the colour of the font used in HeadingLabel
bg – background colour of the HeadingLabel
font – used to give customised fonts to the HeadingLabel text
Label()- This function creates a label that can make text appear on the GUI.
CODE:
root = tkinter.Tk()
root.geometry('600x600')
root.title('ProjectGurukul Roll Dice')
#label to print result
label = tkinter.Label(root, text='', font=('Helvetica', 260))
#label to introduce
label2 = tkinter.Label(root, text='Welcome to ProjectGurukul Dice roll. Click to roll dice ', font=('Helvetica',10))
label2.place(x=150,y=400)
EXPLANATION:
The main function part involves creation of the Tk root widget.
# images
dice = ['die1.png', 'die2.png', 'die3.png',
'die4.png', 'die5.png', 'die6.png']
# simulating the dice with random numbers between
# 0 to 6 and generating image
DiceImage = ImageTk.PhotoImage(Image.open(random.choice(dice)))
Yay! We have successfully developed a cool application – Dice Rolling Simulator in Python. Now, you can just click on a but-
ton and get your next number. Cheers to Python and its package ‘Tkinter’ which supports functions and makes our work
easy. Who would have thought that we can develop an application by only the ‘random’ function of python? As of now, we
w i t h i t s s e c u r i t y guarantees and protocol flexibility can provide a base or more complex game
protocols that include verifiable randomness, increased number o parties, and more efficient proof verification.