Skip to main content

Guessing Game

In this post there is one small easy guessing game in python language. The Guessing Game uses Binary Search Algorithm to guess the number. 

How it Works

It simply returns the mid value every time. It guesses the number depending on what you give input (low or high). If you give low as a input than it updates low value to mid+1. And if you give high as a input than it updates high to mid-1. And it will continue till your guessed number arrived.
 ##############################################################################  
   
 #Author@SPPU CSE GURU  
   
 print("Let's Play Guessing Game")  
   
 def Guessing_Game():  
   input("Take A Number Between 1 to 100 in Your Mind and Press Enter (Don't Enter No.) ")  
     
   high=100  
   low=0  
   while True:  
     guess=(high+low)//2  
     print("Is Your Number",guess)  
     res=str(input("""  
            Enter 'h' if Number is too high  
            Enter 'l' if Number is too low  
            Enter 'c' if Number is correct \n""")).lower()  
     if res=='h' :  
       high=guess-1  
     elif res=='l' :  
       low=guess+1  
     elif res=='c':  
       print("Great Choise",guess)  
       ch=input("Would you like to play again! (y or n)")  
       if ch=='y':  
         Guessing_Game()  
       else:  
         print("Thankyou for Playing Guessing Game")  
         break  
     else:  
       break  
 Guessing_Game()  
 ##############################################################################    
If you find it useful please Comment and Share with your friends. 

Comments

Popular posts from this blog

OOP 2

Object Oriented Programming Group A - Practical : 2 Problem Statement :  Develop a program in C++ to create a database of student’s information system containing the following information: Name, Roll number, Class, Division, Date of Birth, Blood group, Contact address, Telephone number, Driving license no. and other. Construct the database with suitable member functions. Make use of constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete as well as exception handling. Check Out Code Here  ðŸ‘‡ Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

OOP 3

  Imagine a publishing company which does marketing for book and audio cassette versions. Create a class publication that stores the title (a string) and price (type float) of publications. From this class derive two classes: book which adds a page count (type int) and tape which adds a playing time in minutes (type float). Write a program that instantiates the book and tape class, allows user to enter data and displays the data members. If an exception is caught, replace all the data member values with zero values. The code for above problem is as follows: //@author: SPPU CSE GURU #include <iostream> using namespace std; class Publication { private: string title; float price; public: Publication() //constructor { title=""; price=0.0; } Publication(string title, float price) { this->title=title; ...

3D Cube Transformations

  Group C   Practical 6 b   Problem Statement :     Write C++ program to draw 3-D cube and perform following transformations on it using OpenGL i) Scaling ii) Translation iii) Rotation about an axis (X/Y/Z). Check Out Code Here  ðŸ‘‡ Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊