Guess a number
Problem:
"Guess the Number" game. The computer will think of a random number from 1 to 100, and ask you to guess it. The computer will tell you if each guess is too high or too low. You win if you can guess the number within n tries.
Input:
Integer random_number Integer N denoting no of tries. Integer guess
Output:
Win or Loss
Constraints:
1<= guess <= 100
Algorithm
Step1: STARTStep 2: Read random_number between the range 1 and 100.Step 3: Read NStep 4: Read guessStep 5: SET i=1Step 6: WHILE i<=N and guess not equal to random_numberif guess > random_number thenPRINT "Guess is high"elsePRINT "Guess is Low"Read guessSET i=i+1END WHILEStep 7:IF i<=N thenPRINT "WIN"ELSEPRINT "LOSS"Step 8: STOP
##Flowchart
References
- Allen B. Downey, “Think Python: How to Think Like a Computer Scientist‘‘, 2nd edition, Updated for Python 3, Shroff/O‘Reilly Publishers, 2016 (http://greenteapress.com/wp/thinkpython/)
- Guido van Rossum and Fred L. Drake Jr, ―An Introduction to Python – Revised and updated for Python 3.2, Network Theory Ltd., 2011.
- John V Guttag, ―Introduction to Computation and Programming Using Python‘‘, Revised and expanded Edition, MIT Press , 2013
- Robert Sedgewick, Kevin Wayne, Robert Dondero, ―Introduction to Programming in Python: An Inter-disciplinary Approach, Pearson India Education Services Pvt. Ltd., 2016.
- Timothy A. Budd, ―Exploring Python‖, Mc-Graw Hill Education (India) Private Ltd.,, 2015. 4. Kenneth A. Lambert, ―Fundamentals of Python: First Programs‖, CENGAGE Learning, 2012.
- Charles Dierbach, ―Introduction to Computer Science using Python: A Computational Problem-Solving Focus, Wiley India Edition, 2013.
- Paul Gries, Jennifer Campbell and Jason Montojo, ―Practical Programming: An Introduction to Computer Science using Python 3‖, Second edition, Pragmatic Programmers, LLC, 2013.