top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Guess the number of oranges in a box game

Writer's picture: mrbenjaminowusumrbenjaminowusu

This game guesses the number of oranges in a closed box. There is a secret number that when guessed correctly, you win the game. This is a pure game by chance.

I started by setting a secret number to the variable "orange_num" i.e. 13. The number times the game can be played to the variable "guess_count" i.e. 0.The limit at which the user can guess to the variable "guess_limit i.e 3.



orange_num= 13
guess_count=0
guess_limit= 3

Using the while loop, so far as the guess_count is less than the guess_limit, the input function is called to allow the user to choose any number. Then the integer function is called on the number guessed by the user to return the numeric integer equivalent from the input function. Then the guest count is increased by one




while guess_count < guess_limit:
    guess=int(input("Guess number: "))
    guess_count=guess_count+1

An if statement is called inside the while loop. if the guess number is the same as the orange_num. The print statement "YOU WON" returned. Then the break statement is called to break out of the loop.



        if guess == orange_num:
                print("YOU WON")
                break

An else statement is called on the while loop if all the user fails to guess the orange_num. "SORRY, GAME OVER" is printed out.


else:
    print("SORRY, GAME OVER")

An example of the user winning the guess game on the third try is below




Guess number: 1
Guess number: 5
Guess number: 13
YOU WON

0 comments

Recent Posts

See All

Comments


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