0% found this document useful (0 votes)
10 views2 pages

Random Number Guessing Game Code

The document contains a Python code for a guessing game where children have three chances to guess a number generated by the computer between 20 and 30. It utilizes the random module to generate the number and provides feedback on the guesses. Additionally, it includes a simple demonstration of generating a random float number using the random module.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Random Number Guessing Game Code

The document contains a Python code for a guessing game where children have three chances to guess a number generated by the computer between 20 and 30. It utilizes the random module to generate the number and provides feedback on the guesses. Additionally, it includes a simple demonstration of generating a random float number using the random module.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Using Random Module:

CODE:

1. Game for children

import random

count=3

ans='y'

win=False

print("guess what number computer generated between 20-30")

print("Total 3 chances are there")

print("___________________________________________________________")

while ans=='y':

num1=[Link](20,30)

print("change remaining:", count)

guess=int(input("Enter your answer: "))

if num1==guess:

print("Congratulations!, you guessed it right")

win=True

else:

print("wrong!")

count-=1

if count==0:

print("oops!, you lost all your chances")

print("number was:",num1)

if win==True or count==0:

ans==input("play again?")

if ans=='y':

count=3

win=False
OUTPUT:

guess what number computer generated between 20-30

Total 3 chances are there

___________________________________________________________

change remaining: 3

wrong!

change remaining: 2

wrong!

change remaining: 1

wrong!

oops!, you lost all your chances

number was: 30

change remaining: 3

wrong!

change remaining: 2

wrong!

change remaining: 1

wrong!

oops!, you lost all your chances

number was: 26

change remaining: 3

Congratulations!, you guessed it right

2.

import random

a=[Link]()

print(a)

You might also like