You are on page 1of 27

COMPUTER SCIENCE PROJECT REPORT

NUMBER/WORD GUESSING GAME

KALIN ROZARIO.S
Roll no: 7215
12 B
VIDYA MANDIR @ ESTANCIA SCHOOL

Page 1 of 27
ACKNOWLEDGEMENT
I would like to thank our school principal, Mrs.Sankari Ravi, and the school
management for the support they have offered me.

I would like to express my sincere thanks and gratitude to my Computer Science


teacher, Mrs.Vandana Sivaraj who gave me this opportunity to increase my
knowledge on the topic by doing a project on ‘NUMBER/WORD GUESSING
GAME’. I would also like to express my gratitude to the lab teacher, Mrs.Vasantha
Meenakshi, and the lab attendant, Mr.Sarathkumar, whose guidance has helped me
complete this project without any difficulty.

I would also like to thank my family and friends, who helped me collect the needed
information for the project. Their valuable suggestions and guidance have been
helpful in various phases of the completion of the project.

Last but not the least, I would like to thank my teammates, Vishwaswaroop and
Jothimadhavann, for their enthusiastic support and hard work in making this project.

Page 2 of 27
TABLE OF CONTENTS:

S.NO CONTENT PAGE NO.

1. Introduction 4

2. Concepts used 6

3. Source Code 7

4. Output 22

5. Conclusion 26

6. Future development 26

7. Bibliography 27

Page 3 of 27
INTRODUCTION
Python is an interpreted high-level general-purpose programming language. It
supports multiple programming paradigms, including structured, object-oriented,
and functional programming. It was created by Guido Van Rossum in February
1991. It is based on two programming languages:

● ABC language

● Module-3

Its language constructs as well as its object-oriented approach aim to help


programmers write clear, logical code for small and large-scale projects.

The Number/Word Guessing Game is a python-based project. We have developed


the game using Python IDLE. The project’s main aim is to create a simple, yet fun
game. This project contains all the requirements to run a game, including a win-
count system in which the user can save the number of times they won the game by
guessing the number/word correctly before they run out of guesses. The user will be
given a random number of guesses which is decided by an RNG (Random Number
Generator). This project can be used by anyone, regardless of the level of
understanding they have of the program. A very user-friendly UI has been created
with the help of the Tkinter module for efficient and easy gameplay. Effective use
of text files and the Tkinter module is the specialty of this project.

Hardware used

● RAM: 8GB RAM (4GB preferable)


● Disk space: 2 to 3GB

Page 4 of 27
Software used
● Operating System: Processors: Intel® Core™ i5 processor 4300M at 2.60
GHz or 2.59 GHz (1 socket, 2 cores, 2 threads per core)
● Operating systems: Windows* 7 or later, macOS, and Linux
● Python* versions: 2.7.X, 3.6.X or 3.9.X

How to install:

 To play the game without any issues, you need to install our program into the
folder where python generally saves your code.
 If the game still doesn’t work properly, try installing the program in the folder
where you installed Python.
 To access the folder where Python is installed, right-click on the Python IDLE
icon and select “Open file location”.

Page 5 of 27
CONCEPTS USED

BUILT-IN FUNCTIONS:

1) Input() – Allows user input


2) Int() – Returns an integer number
3) Open() – Opens a file and returns a file object
4) Print() – Prints to the standard output device
5) Range() – Returns a sequence of numbers, starting from 0 and increments by
1(by default)
6) Str() – Returns a string object

MODULES:

1) Tkinter – Python's standard GUI (graphical user interface) package


2) Random – Used to generate random numbers
3) Os – Provides functions for interacting with the operating system.
4) Sys - provides various functions and variables that are used to manipulate
different parts of the Python runtime environment.

5) Concepts of file handling in python

Page 6 of 27
SOURCE CODE:

from tkinter import *


from tkinter.ttk import *
import random as rd
from tkinter import messagebox
import os, sys
from stat import *
import os.path

#Creating a tkinter window


root = Tk()
root.title("Guessing Game")
root.geometry("700x600")
name = Label(root, text = "NUMBER/WORD GUESSING GAME", font =
15).place(x = 210, y = 10)
start = Label(root, text = "Press the button to start the game!!", font = 12).place(x =
220, y = 230)
point = 0
str_point = str(point)
guess_No = 0
rand_number = 0
choice = 0

int_var = IntVar()

Page 7 of 27
inputtxt2_var = StringVar()
more_than = "Your number is more than the mystery number!"
less_than = "Your number is less than the mystery number!"
correct = "You Guessed it right!!!!!"
not_valid = "Enter a valid number!!"
out_of = "You are out of guesses. GAME OVER"
sports = ['rugby', 'hockey', 'squash', 'golf', 'football', 'vallam kali', 'basketball',
'cricket']
fruits_vegetables = ['grapes', 'watermelon', 'raisin', 'onion', 'mushroom']
games = ['chess', 'monopoly', 'carrom', 'scrabble']
chess_ch = "A horse jumps over a tower and the tower disappears. it's not an
illusion or a dream. where could this happen? "
monopoly_ch = "The aim of the game is to have the most properties and most
money at the end. the mascot is a guy with a black hat."
carrom_ch = "you put the coins in the pocket. if its yours, you take it. otherwise
you give it. what game is this?"
scrabble_ch = "Put down the words cleverly and get more points. what game is
this?"
rugby_ch = "phrase related to the sport: That is a touchdown!!!! [HARD]"
hockey_ch = "Involves hitting a disk into a net to score [MEDIUM]"
squash_ch = " racket and ball sport played by two players in a four-walled court
with a small, hollow rubber ball [HARD]"
vallam_kali_ch = "this sport is celebrated in Kerala on the festive occasion of
Onam. involves boats [IMPOSSIBLE]"
golf_ch = "objective: to hit a small ball into a small hole. words related to the
sport: Par, Birdie, Bogey [HARD]"
football_ch = "Two teams try to hit a ball in the opponents net. only legs are used
[EASY]"

Page 8 of 27
basketball_ch = "Players are usually very tall and can jump high [MEDIUM]"
cricket_ch = "The name of the sport is derived from the Middle Dutch word
*kricke* [Easy]"
grapes_ch = "I can be red or green and I grow on a vine. I'm dried to make raisins,
or squeezed to make wine. What am I?"
watermelon_ch = "I look green but what you eat is red, and what you spit out is
black. What am I?"
raisin_ch = "I'm wrinkled and people treat me in a different way: they chew or pick
out and throw away. What am I?"
onion_ch = "You cut me, chop me, dice me and cry over me. What am I?"
mushroom_ch = "I'm a room that you can eat. What am I?"
def save_point():
global point
global str_point
if
os.path.exists('C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python39\\p
oint.txt'):
os.chmod("point.txt", S_IRUSR | S_IWUSR | S_IXUSR)
with open("point.txt", 'r') as p:
score = p.read()
with open("point.txt", 'w') as p:
record = int(score)
record+=point
win_count = str(record)
x = p.write(win_count)
points_var.set(record)
point = 0

Page 9 of 27
else:
with open("point.txt", 'w') as p:
os.chmod("point.txt", S_IRUSR | S_IWUSR | S_IXUSR)
x = p.write(str_point)
points_var.set(point)

def ask_for_save():
msg = messagebox.askquestion("SAVE", "Do you want to save the file?", icon =
'question')
if msg == 'yes':
save_point()
else:
messagebox.showinfo('RETURN',"Click the SAVE button when you wish to
save your win count")
def sport_guessing():
if guess_No != 0:
if random_sport == "rugby":
message_var.set(rugby_ch)
elif random_sport == "hockey":
message_var.set(hockey_ch)
elif random_sport == "squash":
message_var.set(squash_ch)
elif random_sport == "vallam kali":
message_var.set(vallam_kali_ch)
elif random_sport == "golf":

Page 10 of 27
message_var.set(golf_ch)
elif random_sport == "football":
message_var.set(football_ch)
elif random_sport == "basketball":
message_var.set(basketball_ch)
elif random_sport == "cricket":
message_var.set(cricket_ch)
elif guess_No == 0:
message_var.set("You are out of guesses. GAME OVER!")

def fruitveg_guessing():
if guess_No != 0:
if random_fruitveg == "grapes":
message_var.set(grapes_ch)
elif random_fruitveg == "watermelon":
message_var.set(watermelon_ch)
elif random_fruitveg == "raisin":
message_var.set(raisin_ch)
elif random_fruitveg == "onion":
message_var.set(onion_ch)
elif random_fruitveg == "mushroom":
message_var.set(mushroom_ch)
elif guess_No == 0:
message_var.set("You are out of guesses. GAME OVER!")

Page 11 of 27
def game_guessing():
global guess_No
if guess_No != 0:
if random_game == "chess":
message_var.set(chess_ch)
elif random_game == "monopoly":
message_var.set(monopoly_ch)
elif random_game == "carrom":
message_var.set(carrom_ch)
elif random_game == "scrabble":
message_var.set(scrabble_ch)
elif guess_No == 0:
message_var.set("You are out of guesses. GAME OVER!")

def sport_checking():
global guess_No
global point
word = inputtxt2_var.get()
if guess_No != 0:
if word.lower() == random_sport:
prompt_var.set("You guessed it right!!!")
point += 1
else:
prompt_var.set("WRONG!!")
guess_No = guess_No - 1

Page 12 of 27
elif guess_No == 0:
prompt_var.set("You are out of guesses. GAME OVER!")

def fruitveg_checking():
global guess_No
global point
word = inputtxt2_var.get()
if guess_No != 0:
if word.lower() == random_fruitveg:
prompt_var.set("You guessed it right!!!")
point += 1
else:
prompt_var.set("WRONG!!")
guess_No = guess_No - 1
elif guess_No == 0:
prompt_var.set("You are out of guesses. GAME OVER!")

def game_checking():
global guess_No
global point
word = inputtxt2_var.get()
if guess_No != 0:
if word.lower() == random_game:
prompt_var.set("You guessed it right!!!")

Page 13 of 27
point += 1

else:
prompt_var.set("WRONG!!")
guess_No = guess_No - 1
elif guess_No == 0:
prompt_var.set("You are out of guesses. GAME OVER!")

def chck_num():
global more_than
global less_than
global correct
global not_valid
global out_of
global guess
global guess_No
global point

if guess_No != 0:
if guess > rand_number:
string_var.set(more_than)
guess_No = guess_No - 1
elif guess < rand_number:
string_var.set(less_than)

Page 14 of 27
guess_No = guess_No - 1
elif guess == rand_number:
string_var.set(correct)
point += 1
else:
string_var.set(not_valid)
elif guess_No == 0:
string_var.set(out_of)

def randguess():
global guess_No
guess_No = rd.randint(1,9)
rand = str(guess_No)
number = Label(top1, text = "No. of guesses: "+rand, font = 11). place(x = 230,
y = 230)

def open_wordguess():
global message_var
global prompt_var
global random_fruitveg
global random_sport
global random_game
top3 = Toplevel(top1)

top3.title("Word Guessing")
Page 15 of 27
top3.geometry("900x600")

random_sport = rd.choice(sports)

random_fruitveg = rd.choice(fruits_vegetables)

random_game = rd.choice(games)

alert = Label(top3, text = "Select which genre you want the word to be from
below: ", font = 12)
alert.place(x = 280, y = 150)

sports_buttn = Button(top3, text = "PICK SPORTS", command =


sport_guessing)
sports_buttn.place(x = 270, y = 260)

fruits_veg = Button(top3, text = "PICK FRUITS & VEGETABLES", command


= fruitveg_guessing)
fruits_veg.place(x = 370, y = 260)

games_buttn = Button(top3, text = "PICK BOARD GAMES", command =


game_guessing)
games_buttn.place(x = 550, y = 260)

message_var = StringVar()
message_var.set("**The Hint will be displayed here**")
Page 16 of 27
message = Label(top3, textvariable = message_var, font = 15)
message.pack()

inputtxt2 = Entry(top3, textvariable = inputtxt2_var, font = 10)


inputtxt2.place(x = 350, y = 200)

sprtcheck_butn = Button(top3, text = "GUESS SPORT", command =


sport_checking)
sprtcheck_butn.place(x = 290, y = 110)

fruitcheck_butn = Button(top3, text = "GUESS FRUIT OR VEGETABLE",


command = fruitveg_checking)
fruitcheck_butn.place(x = 380, y = 110)

gamecheck_butn = Button(top3, text = "GUESS GAME", command =


game_checking)
gamecheck_butn.place(x = 550, y = 110)

prompt_var = StringVar()
prompt_var.set(".")
prompt = Label(top3, textvariable = prompt_var, font = 13)
prompt.pack()

quit_buttn = Button(top3, text = "Return to guesses window", command =


top3.destroy). place(x = 380, y = 500)

top3.resizable(False,False)
Page 17 of 27
def open_numberguess():
global rand_number
global string_var
top2 = Toplevel(top1)

top2.title("Number Guessing")

top2.geometry("700x600")

rand_number = rd.randint(1, 50)

prompt = Label(top2, text = "Guess the number between 1-50", font = 12).
place(x = 220, y = 230)

inputtxt = Entry(top2, textvariable = int_var, font = 10). place(x = 240, y = 270)

string_var = StringVar()

string_var.set("hello")

alert = Label(top2, textvariable = string_var, font = 12)


alert.pack()

enter = Button(top2, text = "Guess", command = lambda: [input_num(),


chck_num()]).place(x = 290, y = 310)

Page 18 of 27
guess = enter

quit_buttn = Button(top2, text = "Return to guesses window", command =


top2.destroy). place(x = 260, y = 500)

top2.resizable(False, False)

def input_num():
global guess
inp = int_var.get()
guess = inp
return inp

def open_guesses():
global top1
top1 = Toplevel(root)
top1.title("No. Of Guesses")
top1.geometry("600x500")

prompt = Label(top1, text = "Click the button to generate a random number of


guesses", font = 13).place(x = 100, y = 150)

gen_No = Button(top1, text = "Generate random number", command =


randguess). place(x = 220, y = 190)

Page 19 of 27
number_btn = Button(top1, text = "Guess a Number", command =
open_numberguess). place(x = 190, y = 260)

word_btn = Button(top1, text = "Guess a Word", command = open_wordguess).


place(x = 320, y = 260)

caution = Label(top1, text = "**Press the Generate random number button


everytime you want to change the game**", font = 13)
caution.pack()

quit_buttn = Button(top1, text = "Return to starting window", command =


top1.destroy). place(x = 220, y = 400)

top1.resizable(False, False)

point_butn = Button(root, text = "Update Win-Count", command = ask_for_save).


place(x = 290, y = 400)

points_var = StringVar()
points = Label(root, textvariable = points_var). place(x = 400, y = 350)
info = Label(root, text = "Your Win Count: ", font = 15). place(x = 250, y = 350)

strt_button = Button(root, text = 'Click here!', command = open_guesses). place(x


= 300, y = 280)

style = Style()

Page 20 of 27
style.configure("BW.TLabel", background = "red", foreground = "white", font =
15)
quit_buttn = Button(root, text = "QUIT", style = "BW.TLabel", command =
root.destroy). place(x = 320, y = 500)

root.resizable(False, False)
root.mainloop()

Page 21 of 27
OUTPUT:

Page 22 of 27
Page 23 of 27
Page 24 of 27
Page 25 of 27
CONCLUSION:
The Number/Word guessing game is a simple yet fun game. Compete with your
friends to see who was the most wins in the game.

FUTURE DEVELOPMENT:
The scope for future developments in the program is very high. The following
developments can be made to the program:
 Making calculations on the probability of random guessing numbers.
 They can be used for analytical study on number theorems, sets and
relations and used in variable generating functions.
 Can be used for specific purposes for captcha generation for passwords.

Page 26 of 27
BIBLIOGRAPHY

1) Sumita Arora Class 12 Computer Science


2) https://www.geeksforgeeks.org/
3) https://support.enthought.com/hc/en-us/articles/204273874-Enthought-
Python-Minimum-Hardware-Requirements
4) https://en.wikipedia.org/wiki/Python_(programming_language)

Page 27 of 27

You might also like