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

cscode

Uploaded by

nikoceus.7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

cscode

Uploaded by

nikoceus.7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Code of the program.

import random as random

print(" WECOME TO NUMBER GUESSING


GAME ")
print("This is a game in which you will guess a number .")
print("You will be awarded 20 points for every correct answer and 10 points will be
deducted for every answer")

tries = 1
Upper_limit = int(input("ENTER UPPER LIMIT : "))
Lower_limit = int(input("ENTER LOWER LIMIT : "))
name = input("ENTER NAME :- ")
score = 0
while tries <= 10:
r = random.randint(Lower_limit, Upper_limit)
num = int(input("Guess a number :-"))
if r == num:
score = score + 20
print("THY WIN")
elif r != num:
score = score - 10
print("THY LOSE")
tries = tries + 1
print("YOUR SCORE IS :-", score)
if score == 200:
print("YOU MAY SAY THAT YOU ARE THE PERFECT HUMAN BEING !!!!!")
elif score == 170:
print("JUST THIS CLOSE !!!!!!")
elif score == 140:
print("NICE!!")
elif score == 110:
print("SATISFACTORY RESULT")
elif score == 80:
print("YOU STILL NEED TO LEARN ALOT .")
elif score == 50:
print("BREAKING EVEN NOW , AREN'T WE ?")
elif score == 20:
print("You are there yet!!!")
elif score == -10:
print("WHY , TRY HARDER!")
elif score == -40:
print("YOU DELIBERATELY LOST RIGHT?!")
elif score == -70:
print("ON THE BRIGHTER SIDE YOU STILL GOT 1 CORRECT.")
else:
print("FATE WANTS YOU TO LOSE , TRY AGAIN AND DEFEAT THY FATE.")

def add_data():
f = open("SCORES.txt", "a+")
f.write(name + "," + str(score) + "\n")
f.close()
add_data()

def printallscores():
f = open("SCORES.txt", "r")
t = f.readlines()
for i in t:
print(i)
f.close()

def printsinglescore():
f = open("SCORES.txt", "r")
o = input("ENTER NAME :- ")
p = -1
t = f.readlines()
for i in t:
data2= i.split(",")
if data2[0] == o:
print(data2[0], "scored", data2[1])
p = 1
if p == -1:
print("You did not play the game my friend as there is no record of the
name provided !")
f.close()

print("TO PRESENT YOU ALL THE SCORES PROVIDED PRESS 1 ")


print("TO PRESENT A SEPCIFIC SCORE PRESS 2")
print("TO EXIT PRESS 3")
ch = 29
while ch != 3:
ch = int(input("PLEASE ENTER THE VALUE :- "))
if ch == 1:
printallscores()
elif ch == 2:
printsinglescore()
else:
ch = 3

You might also like