Developing a Rock Paper Scissors Game using Python

Verified

Added on  2025/04/04

|31
|3846
|107
AI Summary
Desklib provides past papers and solved assignments for students. This assignment details building a Rock Paper Scissors game in Python.
Document Page
OLGA- UNIT 1 PROGRAMMING
(ICN)
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Table of Contents
Table of Figures...............................................................................................................................4
Introduction......................................................................................................................................5
LO1. Define basic algorithms to carry out an operation and outline the process of programming
an application...................................................................................................................................6
P1. Provide a definition of what an algorithm is and outline the process of building an
application....................................................................................................................................6
M1 Determine the steps taken from writing code to execution...................................................7
LO2 Explain the characteristics of procedural, object-orientated and event-driven programming,
conduct an analysis of a suitable Integrated Development Environment (IDE).............................9
P2 Give explanations of what procedural, object-orientated and event-driven paradigms are;
their characteristics and the relationship between them..............................................................9
Event Driven Programming: It is a type of programming paradigm in which action are and
nature of execution is totally depend on the threads, user clicks, queries etc...........................12
M2. Analyse the common features that a developer has access to in an IDE...........................14
LO3 Implement basic algorithms in code using an IDE................................................................15
P3 Write a program that implements an algorithm using an IDE..............................................15
M3 Use the IDE to manage the development process of the program......................................22
LO4 Determine the debugging process and explain the importance of a coding standard...........23
P4 Explain the debugging process and explain the debugging facilities available in the IDE..23
P5 Outline the coding standard you have used in your code.....................................................26
Document Page
M4 Evaluate how the debugging process can be used to help develop more secure, robust
applications................................................................................................................................28
Conclusion:....................................................................................................................................29
References......................................................................................................................................30
Document Page
Table of Figures
Figure 1: Single level Inheritance..................................................................................................11
Figure 2: Multilevel Inheritance....................................................................................................12
Figure 3: Hierarchical Inheritance.................................................................................................12
Figure 4: Hybrid Inheritance.........................................................................................................12
Figure 5: Encapsulation.................................................................................................................13
Figure 6: code 1.............................................................................................................................16
Figure 7: code 2.............................................................................................................................17
Figure 8: code 3.............................................................................................................................18
Figure 9: code 4.............................................................................................................................19
Figure 10: code 5...........................................................................................................................20
Figure 11 : output: 1......................................................................................................................20
Figure 12: output: 2.......................................................................................................................21
Figure 13: output: 3.......................................................................................................................21
Figure 14 : output: 4......................................................................................................................22
Figure 15 : output: 5......................................................................................................................22
Figure 16 : output: 6......................................................................................................................23
Figure 17 Traceback debugging....................................................................................................25
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 18 breakpoints....................................................................................................................26
Figure 19 error...............................................................................................................................26
Figure 20 Naming Convention......................................................................................................27
Figure 21 clean code......................................................................................................................28
Figure 22 comments......................................................................................................................29
Document Page
Introduction
This report is about the game Rock Paper Scissors in which a four-digit number is asking to enter
and then the result is generating according to the entered number is matched with the randomly
generated number. In this report study of various algorithm’s point will be covered. Techniques
of debugging and steps of debugging in this report will also be discussed. Best IDE named as
pyCharm for python will be used for the development of the application.
Document Page
LO1. Define basic algorithms to carry out an operation and outline the
process of programming an application.
P1. Provide a definition of what an algorithm is and outline the process of building
an application.
Algorithm: Algorithms(Cano, et al, 2015) are the set of steps designed for a particular task. Task
can be of any type either multiplication, sorting, or some complex operations. Search engines
perform their task to search most relevant things according to the search index which user enters.
Search engines are the best example of complex trivial algorithms which search the whole
internet according to the user terms.
In programming, algorithms may consider as a function which is designed to perform a particular
task in a well defined and sorted manner. These functions are considered as a whole application
but majorly they are serving small tasks which combined to form whole application. An
application may consider numerous small and big algorithms or function to complete desired
task of the application. During software development, a task can be completed in many ways in
that situation algorithms are designed to perform the task. Among all those algorithms, the
algorithm is selected which has the smallest value of time and space complexity. The main
reason behind the development of algorithms is to minimize the time and space complexities.
Applied Algorithms must have considered as the best way to perform the desired task.
There are four stages to develop algorithms are:
1. Design: This is the first and basic step in the course of development of an algorithm.
Before designing an algorithm developer must identify the function which will be going
to be performed by that algorithm. After the identification of the function developer must
break the whole task into a number of small tasks to obtain the best outcome.
2. Analyze: As till now developer develops a frame of the algorithm. He/She now has to
analyze the functionality of that framework. How efficiently the algorithm is working is
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
looked in this step. This is the step in which modification of algorithm is performed to
remove bugs. Some programmer performs this step before designing the algorithm.
3. Implement: Now the time comes to write the code for the algorithms in the desired
programming language. For the efficient code development developer must know the
exact function of each statement he/she fires. A good algorithm must deal with all types
of input whether wrong or right. There must be no such case remained untouched which
causes application unexpectedly shut down. The algorithm must be designed in such a
way so that less experienced programmer can easily understand. Comments must be
included to notify reader about the function of a particular step.
4. Experiment: An algorithm is now developed this must be debugged efficiently to
remove all types of exception and error. Functioning of an algorithm is going to be
checked on all type of devices before delivering to the end user. Every type of input is
provided to the algorithm to check the smooth running of the algorithm.
After the above steps, one can easily develop a good algorithm. Designing and analysis of an
algorithm is a cyclic process. You can perform any steps again to improve the functioning of the
algorithm and reach the goal of efficiency for the algorithm.
M1 Determine the steps taken from writing code to execution.
Function to check the score:
#define function for checking score
def check_score(num,randNum):
global rock
global paper
global scissors
#checking for scissor where both word are exactly same
if num==randNum:
scissors =+ 1
return 1
#converting user entered four digit number list
num = [int(i) for i in str(num)]
# converting random number to the four digit number list
randNum = [int(i) for i in str(randNum)]
Document Page
#loops for seeing the score
for i in range(4):
for j in range(4):
#if number found is at correct position and correct number
if i==j:
if randNum[i]==num[j]:
rock = rock + 1
break
#if number found is correct but its position is correct
else:
if randNum[i] == num[j]:
paper =paper + 1
break
return 1
In this function, a computer checks the score by matching the user input number to the randomly
generated number and change the global variable according to the matching number. Scissors is
1 if the number is matched with the generated number. It also matches both number’s digit and
their position and provides score according to that. After the score calculation function returns to
the main program.
In this program, one more function is used named as “not_repeated”
#function to check number is of different digit
def not_repeated(num):
#converting number to list of its digits
num = [int(i) for i in str(num)]
#loop start to compare each number
for i in range(0,4):
for j in range(1,4):
#check for location of digit is not same
if i!=j:
#check if digit is same at two different position
if num[i]==num[j]:
return 0
return 1
In this function, a number is checked for the detection of different digit number. It returns 0 if
number has a repeated digit. Here for loop is run only for 4 places because number used here is
only of four digits. This function is also responsible for the generation of a random number of
four different digits. And also validate the user entered number.
Document Page
LO2 Explain the characteristics of procedural, object-orientated and event-
driven programming, conduct an analysis of a suitable Integrated
Development Environment (IDE)
P2 Give explanations of what procedural, object-orientated and event-driven
paradigms are; their characteristics and the relationship between them.
Procedural programming: It is a kind of Imperative language(Neis, et al, 2015), in which
execution depends on the statements. Another type of programming paradigm is Declarative
language (Alur, et al, 2015) in which execution depends on the expression. C, python are the
example of Imperative language. While HTML, SQL queries are the example of declarative
language. If we talk about procedural programming(Jordan, et al, 2015). It is a type of mini
project which calls in between the program execution, as they complete their execution they
return to the next statement from where they call. This ability to reuse the written program
decrease the code complexity in reading and also minimize the size of the program.
Procedural Programming characteristics:
It involves some basic operations like calculation, reading, and printing task.
It separates a big application into small sub-parts called the function. Which combined to
form whole application.
Nearly every function shares data globally.
Procedural programming follows a top-down approach.
In the large program, it consumes a lot of time to get completely executes.
Object-Oriented programming language: Object-oriented programming is programming in
which involves use of classes and objects. Classes are the blueprint of process while object
denotes the physical existence of the classes. This type of programming increase the security of
the application. Program reusability increases by the use of OOPS (Schuster, et al, 2015). There
are various programming languages which support object-oriented programming paradigm are
JAVA, Python, C++ etc.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Characteristics of OOPS:
Inheritance: It is one of the most important features of object-oriented programming in
which code ones are written and use multiple time. Code reusability is easily achieved by
the use of inheritance (Sharma, et al, 2015). It is used to form a relation between classes. In
inheritance there are two classes involved one which is inherited is called parent class and
class which inherit the properties of parent class is known as child class.
Inheritance is further divided into 4 parts:
1. Single: Single level inheritance is the type of inheritance in which a class inherits
the properties a class as shown in below figure.
Figure 1: Single level Inheritance
2. Multilevel: Multilevel inheritance is the type of inheritance in which a class is
inherited by another class and that class is again inherited by another class. Below
figure, it is clearly stated about the meaning of Multilevel inheritance.
Document Page
Figure 2: Multilevel Inheritance
3. Hierarchical: In this type of inheritance a single class is inherited by two classes.
In figure Hierarchical inheritance is clearly stated.
Figure 3: Hierarchical Inheritance
4. Hybrid: In this type of inheritance two classes are inherited by the same class.
This type of inheritance is not shown by java. In below figure it is clearly
denoted.
Figure 4: Hybrid Inheritance
chevron_up_icon
1 out of 31
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]