0% found this document useful (0 votes)
3 views

Python Pbl

Uploaded by

218r1a66f1
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Pbl

Uploaded by

218r1a66f1
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

1

A PBL Report

On

DICE ROLLING SIMULATOR PYTHON GAME

Submitted to CMREC (UGC Autonomous)

In Partial Fulfillment of the requirements for the Award of Degree of

BACHELOR OF TECHNOLOGY

IN

COMPUTER SCIENCE AND ENGINEERING

(Artificial Intelligence and Machine Learning)

Submitted By

CH.RAHUL-218R1A66E5

D.SRI VIDYA-218R1A66F1

M.NANDHINI-218R1A66G8

P.ALEKYA-218R1A66H6

Under the guidance of

Mr. DR.RAJESH TIWARI

Professor, Department of CSE (AI & ML)

Department of Computer Science & Engineering (AI & ML)

CMR ENGINEERING COLLEGE

(Accredited by NBA, Approved by AICTE, NEW DELHI, Affiliated to JNTU, Hyderabad)

Kandlakoya, Medchal Road, R.R. Dist. Hyderabad-501 401)


2022-2023

CMR ENGINEERING COLLEGE

(Accredited by NBA, Approved by AICTE NEW DELHI, Affiliated to JNTU, Hyderabad)

Kandlakoya, Medchal Road, Hyderabad-501 401

Department of Computer Science & Engineering

CERTIFICATE

“DICE ROLLING SIMULATOR PYTHON GAME


This is to certify that the project entitled ” is a bonafide work carried out by

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.

________________ _______________________

Internal Guide Head of the Department

Mrs . T.S. Suhasini Dr. M . KUMARASWAMY

Assistant Professor Professor & HOD

Department of CSE(AI & ML), Department of CSE(AI & ML),

CMREC, Hyderabad CMREC, Hyderabad

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

Brief about python:

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

various modules by browsing through the Python Standard Library documentation.

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

3.1 Import the random and tkinter modules.

3.2 Create the GUI.


3.3 Create the dice roll function and the button

3.4 Call the GUI.

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

3.1-Importing the required modules

We will import the following modules:

 Tkinter: Imported to use Tkinter and make GUI applications.


 Image, Imagetk: Imported from PIL, i.e. Python Imaging Library. We use it to perform operations involving images

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.

3.3 Create the dice roll function and the button:

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:

button = tkinter.Button(root, text='roll dice', foreground='red', command=roll_dice)


button.pack()
root.mainloop()

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

.pack() – Used to pack the widget onto the root window

3.4 Call the GUI:

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.

Discover related topics:


 TK
 NUMBER
 PYTHON
 ROLL
 THR CANVAS
SOURCE CODE:

# Adding label into the frame


BlankLine = tkinter.Label(root, text="")
BlankLine.pack()

# adding label with different font and formatting


HeadingLabel = tkinter.Label(root, text="Hello from DataFlair!",
fg = "light green",
bg = "dark green",
font = "Helvetica 16 bold italic")
HeadingLabel.pack()

# 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)))

# construct a label widget for image


ImageLabel = tkinter.Label(root, image=DiceImage)
ImageLabel.image = DiceImage

# adding button, and command will use rolling_dice function


button = tkinter.Button(root, text='Roll the Dice', fg='blue', command=rolling_dice)

# pack a widget in the parent widget


button.pack( expand=True)
# construct a label widget for image
ImageLabel = tkinter.Label(root, image=DiceImage)
ImageLabel.image = DiceImage

# packing a widget in the parent widget


ImageLabel.pack( expand=True)

# function activated by button


def rolling_dice():
DiceImage = ImageTk.PhotoImage(Image.open(random.choice(dice)))
# update image
ImageLabel.configure(image=DiceImage)
# keep a reference
ImageLabel.image = DiceImage

# adding button, and command will use rolling_dice function


button = tkinter.Button(root, text='Roll the Dice', fg='blue', command=rolling_dice)

# pack a widget in the parent widget


button.pack( expand=True)

# call the mainloop of Tk


# keeps window open
root.mainloop()
SCREEN SHORTS:
CONCLUSION:

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

have an understanding of Python, Tkinter , and random function. W e h a v e d e s i g n e d a n d i m p l e m e n t e d D i c e

R o l l i n g S i m u l a t o r - w i t h - S t a t e t o p r o v i d e a verifiable, decentralized, game platform . Now you can

simply click on a button and get your next number on dice. I t i s o u r h o p e t h a t t h i s g e n e r a l p l a t f o r m

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.

You might also like