You are on page 1of 12

FEDERAL UNIVERSITY OF LAFIA

FACULTY OF COMPUTING
DEPARTMENT OF COMPUTER SCIENCE
CSC 318 (STRUCTURED PROGRAMMING)

By:
2031700071
LAWRENCE FAVOUR TREASURE

A RANDOM NUMBER GENERATOR/GUESSING


GAME CONSOLE APP WITH PYTHON
TABLE OF CONTENTS

TITLE PAGE

TABLE OF CONTENTS

CHAPTER ONE: INTRODUCTION

PYTHON PROGRAMMING

CHAPTER TWO: PROJECT DEVELOPED AND CHALLENGES ENCOUNTERED

PROJECT DEVELOPED

CHALLENGE ENCOUNTERED

CHAPTER THREE: CONCLUSION AND REFERENCE

CONCLUSION

REFERENCE
CHAPTER ONE
INTRODUCTION

Python Programming
Python is a general purpose, high-level, interpreted, interactive and object-oriented scripting
language created by Guido Van Rossum. The syntax and structure is extremely simple to read
and follow, most of which can be understood even if you do not know any programming.

The python interpreter is easily extended with new functions and data types implemented in C
or C++ (or other languages callable from C). Python is also suitable as an extension language for
customized applications. With python you can do GUI development, Web application, System
administration tasks, Data Analysis, Visualization and much more.

Most programming languages use certain characters or keywords to group statements like
below

'{....}’: for language like C, C++< JAVA etc.

do ... done

if ... fi

begin ... end

Python uses a different principle. Programs get structured through indentation, this means that
code blocks are defined by their indentation, i.e. all statements with the same distance to the
right belong to the same block of code and indentation is done by clicking on tab once or
clicking on space four times.

You can write python in two different ways which are:

Interactive Mode Programming

Script Mode Programming

INTERACTIVE MODE PROGRAMMING

With the Python interactive interpreter, it is easy to check Python commands. The Python
interpreter can be invoked by typing the command "python" without any parameter followed
by the "return" key at the shell prompt and rings up the following prompt.
Fig. 1.0 PYTHON WINDOW

SCRIPT MODE PROGRAMMING

To invoke the interpreter with script, you need to save your python program in a file with an
extension .py and then run the below command to execute the program.

For example:

Type your source code in test.py file

print("Hello, World!")

This will print "Hello World!" on console.


CHAPTER TWO
PROJECT DEVELOPED

With my familiarity with the basics of python programming syntax, I was able to develop a
random number generator/quiz game. This is a python console application.

Random Number Generator/Quiz Game:

A random number generator is used to generate random numbers to create a list, based on your
specifications. The random numbers are interchanged randomly using the random.randint()
function.

This python console application is an app which asks the player to input his/her name, then asks
the player to guess a number, for the player to advance to the next level the player has to guess
the right number else he/she gets stuck in the 1st level. If the number which the user picks
matches the number that has been generated it displays, you guessed it. If the number is
picked by the player is less than the number generated by the computer it displays, guess too
low and if the number chosen by the user exceeds the number generated by the computer is
displays, guess too high.

The quiz game asks the user some familiar question, when the user selects an option it takes
user to the next question. At the end of the questioning it displays the options the user selected
and matches it with the appropriate options. If the option selected by the user is similar to the
option the system displays, it displays the user score and gives an option to play again or end
game.

Here is a list of statements used in this console application

import statement

random.randint() function

while statement

if statement

elif statement

else statement

break statement
The Import Statement

This is the 1st statement I used in my code. This fig.1.5 Program Interface

function imports modules in a program using the statement import.

The imports a module called random.randint().which will help in generating random numbers.

Fig. 1.2 Syntax for Importing Modules.

The random.randint () Function:

This function stores the return value in number. The randint() function is provided by the
random module, so it has to be written as random,randint(),the randint() function returns a
random integer between the two integer arguments passed to it. It generates the secret
number the player is trying to guess.
Fig. 1.3 random.randint() Function

Print() and Input() Function :

This function displays text on the screen and gets text from the keyboard. It is called the I/O .

Fig.1.4 Print () and Input() Function

Interface of my Project

Fig.1.5 Program Interface


Fig.1.6 Program Interface
Fig.1.7 Program Interface

CHALLENGES ENCOUNTERED

During the course of my project here are some problems I encountered:

Indentation Error:

When coding I placed an indentation in the wrong place, and sometimes I left white spaces
between lines of code.

Solution: I made sure to avoid placing indentation in the wrong areas and also limited the
way I made the white spaces.
Fig.1.6 Indentation Error

Name Error:

During the course of my coding I made a lot of errors but one very important one is the
name error, i failed to name some objects while coding and thus it threw an object not
found error.

Solution:

I made sure to declare every class and object to avoid the name error.

Fig. 1.7 Name Error


CHAPTER THREE

CONCLUSION

My project has been successful in the area of generating random numbers for
my console application developed using Python programming language.

Python has made me a better programmer and I have been able to debug and
correct errors developed in the course of my project.

My knowledge on the basics of python has drastically enhanced in the course


of the console application development.
REFERENCE
Python Tutorials Teacher. (2021). Learning Python Programming.
https://www.tutorialsteacher.com/python/python-overview

Python programming language.(2020).Introduction to Python programming.


https://www.learnpython.org/Python
Lutz, M. (2013). Learning Python (Fifth Edition. ed) . Beijing : O’Relly.

You might also like