You are on page 1of 31

DICE ROLLING SIMULATOR USING PYTHON

A MINOR PROJECT SUBMITTED IN THE PARTIAL FULFILLMENT OF


THE REQUIREMENT
FOR THE AWARD OF DEGREE OF
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
BY

JAGRIT SAHNI

University Roll No. 6319011

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


GURU NANAK INSTITUTE OF TECHNOLOGY , MULLANA
AFFILATED TO
KURUKSHETRA UNIVERSITY , KURUKSHETRA , HARYANA
2019-23

CANDIDATE’S DECLARATION
I hereby certify that the work which is being presented in this Project entitled “Dice Rolling
Simulator Using Python ” in partial fulfillment of requirement for the award of degree of B.
Tech., Computer Science and Engineering submitted in Department of Computer Science &
Engineering at Guru Nanak Institute of Technology, Mullana, Ambala affiliated to Kurukshetra
University , Kurukshetra is an authentic record of my work carried out under the supervision of
Mr Sidharth Arora Head of Department, Department of CSE ,GNIT, Mullana, Ambala.

TEJBIR RANA SIDHARTH ARORA


Asst. Professor Head of Department
Department of CSE
GNIT
Mullana

ABSTRACT

The specification Device Identity Composition Engine (DICE) provides a novel basis for remote
attestations specifically suitable in the IoT context. Its purpose is to provide means for remote
attestations to devices that are too size-, cost-, energy-or otherwise constrained to have
Trusted Platform Module attached. This paper gives a short explanation of DICE and compares
different approaches for building up a remote attestation protocol based on it, using symmetric
and asymmetric cryptography .Based on this comparison a symmetric attestation protocol is
proposed for most resource constrained devices and its implications for attestation servers are
discussed. Furthermore a feasibility study is conducted mapping the DICE and the proposed
DICE-based attestation approach to commercial off-the-shelf (COTS) hardware --namely
Arduino Uno in this case --and measurement of the code size, binary size and added
computational requirements is provided. The security of the mapping approach is evaluated
and its advantages and pit falls are demonstrated. The goal is to show how DICE-based
approaches can be mapped to existing hardware and how a more secure IoT environment can
be established on already deployed devices without changes to the hardware.

TABLE OF FIGURES
Figures Title

Fig 1.1 Dice Rolling Simulator Image

Fig 1.2 Dice Image

Fig 2.1 Python logo

Fig 2.2 Python setup


Fig 3.1 Python release for window

Fig 3.2 Python Installation

Fig 3.3 Python installation

Fig 3.4 Cmd-Verify Python was installed

Fig 3.5 Cmd-Verify pip was installed

Fig 3.6 Run App

Fig 3.7 Edit system variable

Fig 3.8 Pycharm window

Fig 4.1 Trial.py file

Fig 4.2 Trial.py code

Fig 4.3 QR project.py file

TABLE OF CONTENTS
Particulars
Abstract
Table of figures
Chapter 1
1.Introduction
1.1 Overview
1.2 Tkinter
1.3 Steps Involved

Chapter 2
Technology
1. Python 3.0
2. Installation
3. Reason of using python

Chapter 3
System Design
1. python 3 Installation On window
2. Pycharm 29
1.Features of pycharm
2.Built in develpoer tools
3.Web Development

Chapter 4
System design and implementation
1.trial.py
2.qr project.py

Chapter 5
Dice Rolling Simulator code
Conclusion
Future scope
References

CHAPTER -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 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.
Fig 1.1

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 Interface and is easy to use. Also, you develop an
application; you can use it on any platform, which reduces the need of
amendments required to use an app on Windows, Mac, or Linux.

Build Dice Rolling Simulator-


Steps –
Step 1: Importing the required modules
Step 2: Building a top-level widget to make the main window for
our application
Step 3: Designing the buttons
Step 4: Forming a list of images to be randomly displayed
Step 5: Constructing a label for image, adding a button and
assigning functionality
Step 6: Forming a list of images to be randomly displayed

Fig 1.2

CHAPTER -2
Technology Used
2.1 Python3.0

fig.2.1

• Python is dynamically-typed and garbage-collected .It


supports multiple programming paradigms ,including
structured, object-oriented and functional programming .Python is often
described .
• Python is dynamically-typed and garbage-collected. It supports multiple
programming paradigms, including structured (particularly, procedural), object-
oriented and functional programming. Python is often described as a "batteries
included" language due to its comprehensive standard library.
• Developer: Python Software Foundation
• License: Python Software Foundation License
• Paradigm: Multi-paradigm: object-oriented

• Python is a widely used high-level programming language for general-


purpose programming, created by Guido van Rossum and first released in 1991. An
interpreted language, Python has a design philosophy that emphasizes code
readability (notably using whitespace indentation to delimit code blocks rather than
curly brackets or keywords), and a syntax that allows programmers to express
concepts in fewer lines of code than might be used in languages such as C++ or Java.
The language provides constructs intended to enable writing clear programs on on
both a small and large scale

Python features a dynamic type system and automatic memory management and
supports multiple programming including object-oriented, imperative, functional
programming, and procedural styles. It has a large and comprehensive standard
library.
Python interpreters are available for many operating systems, allowing Python
code to run on a wide variety of systems. C Python, the reference implementation
of Python, is open source software and has a community-based development
model, as do nearly all of its variant implementations. C Python is managed by the
non-profit Python Software Foundation The Python Software Foundation (PSF) is
a 501(c)(3) non-profit corporation that holds the intellectual property rights behind
the Python programming language.

We manage the open source licensing for Python version 2.1 and later and own and
protect the trademarks associated with Python. We also run the North American
PyCon conference annually, support other Python conferences around the world,
and fund Python related development with our grants program and by funding
special.

Python might not have bright years in the past years (which is mainly launch in the
year 1991) but it has seen a continuous and amazing trend of growth in the 21st
century. This stack overflow graph of major programming languages’ growth
exclusively depicts the steady progress of the PYTHON!

The growth rate of python was not something easy to achieve. Python programming
language is better used for app development, web app or web development, game
development, scientific computing, system administration, etc.
There are several traits of this programming tool which has provided it with an
incredibly successful journey. Python has a main role in the new-edge technologies of
current and upcoming times like ML and AI.
2.2 Installing

Installing Python is generally easy, and nowadays many Linux and UNIX distributions
include a recent Python. Even some Windows computers (notably those from HP) now
come with Python already installed. If you do need to install Python and aren't
confident about the task you can find a few notes, but installation is unremarkable on
most platforms.

Python 3 Installation on Windows


Step 1: Select Version of Python to Install. ...
Step 2: Download Python Executable Installer. ...
Step 3: Run Executable Installer. ...
Step 4: Verify Python Was Installed On Windows. ...
Step 5: Verify Pip Was Installed. ...
Step 6: Add Python Path to Environment Variables (Optional).
Four Python 3.9 installers are available for download - two each for the 32-bit and 64-
bit versions of the interpreter. The web installer is a small initial download, and it will
automatically download the required components as necessary. The offline installer
includes the components necessary for a default installation and only requires an
internet connection for optional features. See Installing Without Downloading for other
ways to avoid downloading during installation.
After starting the installer, one of two options may be selected:
If you select “Install Now”:

•You will not need to be an administrator (unless a system update for the C
Runtime Library is required or you install the Python Launcher for
Windows for all users)

fig 2.2

2.3 Reasons Why You Must Consider Writing Software Applications in Python

1) Readable and Maintainable Code


While writing a software application, you must focus on the quality of its source
code to simplify maintenance and updates. The syntax rules of Python allow you
to express concepts without writing additional code. At the same time, Python,
unlike other programming languages, emphasizes on code readability, and allows
you to use English keywords instead of punctuations. Hence, you can use Python
to build custom applications without writing additional code. The readable and
clean code base will help you to maintain and update the software without putting
extra time and effort.

2) Multiple Programming Paradigms

Like other modern programming languages, Python also supports several


programming paradigm. It supports object oriented and structured programming
fully. Also, its language features support various concepts in functional and
aspect oriented programming. At the same time, Python also features a dynamic
type system and automatic memory management. The programming paradigms
and language features help you to use Python for developing large and complex
software applications.

3) Compatible with Major Platforms and Systems

At present, Python is supports many operating systems. You can even use Python
interpreters to run the code on specific platforms and tools. Also, Python is an
interpreted programming language. It allows you to you to run the same code on
multiple platforms without recompilation. Hence, you are not required to
recompile the code after making any alteration. You can run the modified
application code without recompiling and check the impact of changes made to
the code immediately. The feature makes it easier for you to make changes to the
code without increasing development time.
4) Robust Standard Library

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.

5) Adopt Test Driven Development


You can use Python to create prototype of the software application rapidly. Also,
you can build the software application directly from the prototype simply by
refactoring the Python code. Python even makes it easier for you to perform coding
and testing simultaneously by adopting test driven development (TDD) approach.
You can easily write the required tests before writing code and use the tests to
assess the application code continuously. The tests can also be used for checking if
the application meets predefined requirements based on its source code.
However, Python, like other programming languages, has its own shortcomings. It
lacks some of the built-in features provided by other modern programming
language. Hence, you have to use Python libraries, modules, and frameworks to
accelerate custom software development. Also, several studies have shown that
Python is slower than several widely used programming languages including Java
and C++. You have to speed up the Python application by making changes to the
application code or using custom runtime. But you can always use Python to speed
up software development and simplify software maintenance.
•Python will be installed into your user directory

•The Python Launcher for Windows will be installed according to the option at the
bottom of the first page

•The standard library, test suite, launcher and pip will be installed

•If selected, the install directory will be added to your PATH

•Shortcuts will only be visible for the current user

CHAPTER-3

SYSTEM DESIGN

3.1 Python 3 Installation on Windows

Step 1: Select Version of Python to Install


The installation procedure involves downloading the official Python . exe installer and running
it on your system.
The version you need depends on what you want to do in Python. As we are one
step towards python ,so it is better to download both the latest version of python 2 and
3. working with python 2 enables you to work on older projects or test new projects for
backward compatibility.

Step 2: Download Python Executable Installer

1. Open your web browser and navigate to the Downloads for Windows section of the
official Python website
2.Search for your desired version of Python. At the time of publishing this article, the
latest Python 3 release is version 3.7.
while the latest Python 2 release is version 2.7.16.
3. Select a link to download either the Windows x86-64 executable installer or
Windows x86 executable installer. The download is approximately 25MB.

Fig 3.1 Step 3: Run Executable Installer

1. Run the Python Installer once downloaded.


2.Make sure you select the Install launcher for all users and Add Python 3.7
to PATH checkboxes. The latter places the interpreter in the execution path.
For older versions of Python that do not support the Add Python to Path
checkbox 3. Select Install Now – the recommended installation options.

fig 3.2
4. The next dialog will prompt you to select whether to Disable path length
limit. Choosing this option will allow Python to bypass the 260-character
MAX_PATH limit. Effectively, it will enable Python to use long path names.
fig3.3

Step 4: Verify Python Was Installed On Windows

• Navigate to the directory in which Python was installed on the


system.
• Double-click python.exe.

• The output should be similar to what as we see below:


fig 3.4
Step 5: Verify Pip Was Installed

Pip is a powerful package management system for Python software packages.


Thus, make sure that you have it installed.
We recommend using Pip for most Python packages, especially
when working in virtual environments. To verify whether Pip
was installed:

•Open the Start menu and type “cmd.”


•Select the Command Prompt application.
• Enter pip -V in the console. If Pip was installed successfully, you should see the
following output:
fig 3.5
Step 6: Add Python

Path to Environment

Variables (Optional) •

Open the Start menu

and start the Run app

fig 3.6

•Type sysdm. cpl and click OK. This opens the System Properties window.
•. Navigate to the Advanced tab and select Environment Variables.
•. Under System Variables, find and select the Path variable.
•. Click Edit.
•. Select the Variable value field. Add the path to the python.exe file
preceded with a semicolon (;). For example, in the image below, we
have added “;C:\Python34.”

fig3.7

7. Click OK and close all windows


2. PYCHARM
PyCharm is an integrated development environment (IDE) used in
computer programming, specifically for the Python language. It is
developed by the Czech company JetBrains (formerly known as IntelliJ).
It provides code analysis, a graphical debugger, an integrated unit tester,
integration with version control systems (VCS es), and supports web
development with Django as well as data science with Anaconda
1. Features of pycharm
Intelligent Coding Assistance
PyCharm provides smart code completion, code inspections, on-the-fly error
highlighting and quick-fixes, along with automated code refactorings and
rich navigation capabilities.

Intelligent Code Editor


PyCharm’s smart code editor provides first-class support for Python,
JavaScript, Coffee Script, TypeScript, CSS, popular template languages
and more. Take advantage of language-aware code completion, error
detection, and on the-fly code fixes!
Smart Code Navigation
Use smart search to jump to any class, file or symbol, or even any IDE
action or tool window. It only takes one click to switch to the declaration,
super method, test, usages, implementation, and more.

Fast and Safe Refactorings


Refactor your code the intelligent way, with safe Rename and Delete, Extract
Method, Introduce Variable, Inline Variable or Method, and other refactorings.
3.2.2 BUILTIN DEVELOPERTOOLS
PyCharm’s huge collection of tools out of the box includes an integrated debugger and test
runner; Python profiler; a built-in terminal; integration with major VCS and built-in
database tools; remote development capabilities with remote interpreters; an integrated ssh
terminal; and integration with Docker and Vagrant.

1. Debugging, Testing and Profiling


Use the powerful debugger with a graphical UI for Python and JavaScript. Create and
run your tests with coding assistance and a GUI-based test runner. Take full control of
your code with Python Profiler integration

.
2. VCS, Deployment and Remote Development
Save time with a unified UI for working with Git, SVN, Mercurial or other version control
systems. Run and debug your application on remote machines. Easily configure automatic
deployment to a remote host or VM and manage your infrastructure with Vagrant and
Docker.

3. Database tools
Access Oracle, SQL Server, PostgreSQL, MySQL and other databases right from the IDE.
Rely on PyCharm’s help when editing
SQL code, running queries, browsing data, and altering schemas.
3.2.3 WEB DEVELOPMENT
In addition to Python, PyCharm provides first-class support for various Python web
development frameworks, specific template languages, JavaScript, CoffeeScript,
TypeScript, HTML/CSS, AngularJS, Node.js, and more.

Python Web frameworks


PyCharm offers great framework-specific support for modern web development
frameworks such as Django, Flask, Google App Engine, Pyramid, and web2py, including
Django templates debugger, manage.py and appcfg.py tools, special autocompletion and
navigation, just to name a few.

JavaScript & HTML


PyCharm provides first-class support for JavaScript, Coffee Script, TypeScript, HTML and
CSS, as well as their modern successors.
The JavaScript debugger is included in PyCharm and is integrated with the Django
server run configuration.

Live Edit
Live Editing Preview lets you open a page in the editor and the browser and see the changes
being made in code instantly in the browser. PyCharm auto-saves your changes, and the
browser smartly updates the page on the fly, showing your edits.
Live Edit
Live Editing Preview lets you open a page in the editor and the browser and see the
changes being made in code instantly in the browser. PyCharm auto-saves your
changes, and the browser smartly updates the page on the fly, showing your edits.

3.2.4 HOW TO USE PYCHARM FOR THE FIRSTTIME


To run PyCharm, find it in the Windows Start menu or use the desktop shortcut. You can
also run the launcher batch script or executable in the installation directory under bin.
When you run PyCharm for the first time, some steps are required to complete the
installation, customize your instance, and start working with the IDE.

•Select the user interface theme


Select whether you want to use the default Darcula or Light theme.
•Download and install additional plugins
•If necessary, click Plugins in the left-hand pane and download and install additional
plugins from the PyCharm plugins repository.

Start a project in PyCharm


On the Welcome screen, you can do the following:
• Create a new project
• Open an existing project or file
•Check out an existing project from a version control system
CHAPTER -4
SYSTEM DESIGN AND IMPLEMENTATION

GUI Dice Roll Simulation using Python

Let’s create a dice roll simulation code using the Python tkinter library.
We all love playing board games like snakes and ladders, ludo our
utmost favorite one. But what if you don’t have a dice or you lost it
somewhere. It’s a major mood off for everyone who is excited to play
along.

Using the Tkinter Library in Python for Drawing Dice


Python offers various packages to design the Graphical User
Interface. Tkinter is the most popular, common, faster, and easy to use
Python package used to build GUI applications.
It provides a powerful Object-Oriented Interface and is easy to use. Also,
you develop an application; you can use it on any platform, which
reduces the need of amendments required to use an app on Windows,
Mac, or Linux.

This framework provides Python users with a simple way to create GUI


elements using the widgets found in the Tk toolkit.

Tk widgets can be used to construct buttons, menus, data fields, etc. in


a Python application.
For the dice roll simulation program to run successfully and for building
up GUI, you must import the python tkinter library.
If its not already installed on your system using the pip package
manager:

pip install tk

Coding the Dice Roll Simulation in Python


Here’s the complete code for the program. We’ll break down the
individual sections below, to help you better understand the code.
#import the required libraries
#tkinter library to create GUI
#random library because we're randomly selecting numbers
from tkinter import *
import random
 
#create tkinter instance
root=Tk()
#define geometry
Root .geometry("400x400")
 
#GUI will have two basic components
#1.Button which will trigger the rolling of dice
#2.Dice label
l1=Label(root ,font=("Helvetica",260))
 
def roll():
    #create a number variable in which the list of all the ASCII characters of the string will be
stored
    #Use backslash because unicode must have a backslash
    dice=['\u2680','\u2681','\u2682','\u2683','\u2684','\u2685']
    #configure the label
    l1.config(text=f'{random.choice(dice)}{random.choice(dice)}')
    l1.pack()
     
b1=Button(root,text="Roll the Dice!",foreground='blue',command=roll)
b1.place(x=300,y=0)
b1.pack()
 
root. main loop()

Understanding the Code


#import the required libraries
#tkinter library to create GUI
#random library because we're randomly selecting numbers
from tkinter import *
import random
Initially we import the necessary libraries in python. To get access to
the random module, we add from random import * to the top of our
program. from Tkinter import * imports every exposed object in Tkinter into
your current namespace.

#create tkinter instance


root=Tk()
#define geometry
Root .geometry("400x400")

 root = Tk( ) : The root window is created. The root window is a main
application window in our programs. It has a title bar and borders. These
are provided by the window manager. It must be created before any
other widgets.
 Root . geometry(“400×400”) : The geometry method sets a size for the
window and positions it on the screen. The two parameters are the
width and height of the window.

def roll():
    #unicodes must have a backslash
    dice=['\u2680','\u2681','\u2682','\u2683','\u2684','\u2685']
    l1.config(text=f'{random.choice(dice)}{random.choice(dice)}')
    l1.pack()

We will now define our function roll( ) to create our dice roll simulation.
Now we will create a dice variable in which we will store the list of all
the ASCII characters of that string will be stored.
We will then congif the label.

The choices() method returns a list with the randomly selected element


from the specified sequence. The l1.pack( ) is a geometry manager that
organizes widgets in blocks before placing them in the parent widget.
Root .main loop( ): Finally, we enter the main loop. The event handling
starts from this point. The main loop receives events from the window
system and dispatches them to the application widgets. It is terminated
when we click on the close button of the title bar.
CHAPTER -5
DICE ROLLING SIMULATOR CODE
OUTPUTS-
Conclusion

We have designed and implemented Dice Rolling Simulator-with-State to provide a


verifiable, decentralized, game platform. Now you can simply click on a button and get
your next number on dice. It is our hope that this general platform with its security
guarantees and protocol flexibility can provide a base for more complex game protocols
that include verifiable randomness, increased number of parties, and more efficient proof
verification.

Future Scope
In this project we have used the random module for this ,since we want to randomize the
numbers we get from the dice. It can be further improved by making a attractive graphical user
interface or any other upgradation to this that it can be supported in most of the device.
Beginner s of games or any gamer can easily get its concept and plays it because it is fully user
friendly. We are still working on implementing some graphical interface.

Reference
www.iotwebplanet.com ›
pypi.org ›
www.asp.com.au›

https://www.scribd.com/presentation/410927469/Dice-Rolling-Simulator-Using-
Python-PPT
.

You might also like