Sei sulla pagina 1di 8

Islington College

Kamal Marg, Kamalpokhari, Kathmandu

Computer Programming Guess Number

Submitted By:
Rupak Bista [12063423]

Submitted To:
Mr. Sailesh Neupane

Table of content
Introduction.......................................................................................1 Screenshots Instruction for playing the game................................................2 Random number display.............................................................2 Prompt to input user numbers.....................................................2 Check for number........................................................................3 Output if correct...........................................................................3 Coding..........................................................................................4 - 6

Introduction
This is a Guessing Numbers Game. In this game computer generates five random numbers between 1 - 100. These random numbers are displayed for five second only and then those numbers are hidden after five second. After that, player has to input those numbers in series as displayed earlier. The numbers entered by the player should be correct and in correct order, in order to win the game. After the player wins the game then the player is awarded with $ 10. If the player wins many games then the prize won will be added in his account continuously. The player should enter the numbers correctly; simple mistake can led to loss of the game. Player can play the game as many times s/he wants to play else can exit the game.

-1-

Screenshots
Instruction for playing the game

Random number display

Prompt to input user numbers

-2-

Check for number

Output if correct

-3-

Coding
#rupak bista #may 2013 # it i a memory game from random import randrange import time from string import lower import os print"Welcome To Game" print "please read the insruction carefully before playing the memory game" time.sleep(3) print "At first, the computer displayes five random numbers from 1 to 100." time.sleep(1) print "The numbers are displayed only for five seconds and the numbers are hidden" time.sleep(1) print "you have to input the five numbers in series as printed earlier!" time.sleep(1) print "Each game costs $1, the winner will be awarded a total prize of $10." time.sleep(1) gameplayed=0 gamelose=0 gamewon=0 point=0 #prints the five random numbers a=randrange(1,101) b=randrange(1,101) c=randrange(1,101) d=randrange(1,101) e=randrange(1,101) numr=[a,b,c,d,e] print"Five random numbers are:" print numr time.sleep(5) os.system('cls' if os.name=='nt' else 'clear') print"Enter the numbers in series" num1=input("Enter the first number:") num2=input("Enter the second number:") num3=input("Enter the third number:") num4=input("Enter the fourth number:") num5=input("Enter the fifth number:")
-4-

numu=[num1,num2,num3,num4,num5] print"The number you enter =",numu if numr==numu: print"\nCongratulation you won the game" gamewon=gamewon+1 point=point+10 else: print"\n Sorry, You lose the game" gamelose=gamelose+1 gameplayed=gameplayed+1 print"\nTotal no of game you played =",gameplayed print"\nTotal no of game you lose =",gamelose print"\nTotal no of game you won =",gamewon print"\nTotal point you gain $=","$",point print"\nEnter 'y' to play game again and 'n' to quit:" choice=raw_input("Enter the choice (y/n):") while lower(choice)=="y": print"Five random numbers are:" a=randrange(1,101) b=randrange(1,101) c=randrange(1,101) d=randrange(1,101) e=randrange(1,101) numr=[a,b,c,d,e] print numr time.sleep(5) os.system('cls' if os.name=='nt' else 'clear') print"Enter the numbers in series" num1=input("Enter the first number:") num2=input("Enter the second number:") num3=input("Enter the third number:") num4=input("Enter the fourth number:") num5=input("Enter the fifth number:") numu=[num1,num2,num3,num4,num5] print"The number you enter =",numu if numr==numu: print"\nCongratulation you won the game" gamewon=gamewon+1 point=point+10 else: print"\nSorry You lose the game"
-5-

print "better luck next time" gamelose=gamelose+1 gameplayed=gameplayed+1 print"\nTotal no of game you played =",gameplayed print"\nTotal no of game you won =",gamewon print"\nTotal no of game you lose =",gamelose print"\nTotal point you gain $ =","$",point print"\nEnter 'y' to play game again and 'n' to quit:" choice=raw_input("Enter the choice(y/n):")

-6-

Potrebbero piacerti anche