top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Guessing Game in python

Writer's picture: Omnia SayedOmnia Sayed

Guessing game becomes an interesting technique which can be implemented by English teachers to teach speaking. Beside rising so much fun, guessing games is believed could increase the students’ speaking skill.


This is going to be a simple guessing game where the computer will generate a random number between 1 to 10, and the user has to guess it in 5 tries.


follow the step in a game:


First Step:

Make import to random

import random

number = random.randint(1, 10)

Second Step:

Ask a user its name.

player_of_name = input("Hello, What's your name?")

number_of_guess = 0

print('okay! '+ player_of_name+ ' I am Guessing a number between 1 and 10:')


Third Step:

Make a loop and put condition of a game

while number_of_guess < 5:

guess = int(input())

number_of_guess += 1

if guess < number:

print('Your guess is too low')

if guess > number:

print('Your guess is too high')

if guess == number:

break

Fourth Step:

if guess equal random number we told a player number of tries

and if he can't guess we also told him number of tries and he can't guess more than 5 tries

if guess == number:

print('You guessed the number in ' + str(number_of_guess) + ' tries!')

else:

print('You did not guess the number, The number was ' + str(number))


Finally the output:

Hello, What's your name?Omnia
okay! Omnia I am Guessing a number between 1 and 10:
3
Your guess is too low
6
Your guess is too high
5
You guessed the number in 3 tries!
1 comment

Recent Posts

See All

1 Comment


Data Insight
Data Insight
Sep 21, 2021

Your code should be in a code snippet just as you put the output in a code snippet.

Like

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page