AssignmentThis assignment is to make your computer program guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.
The algorithm used in this assignment is called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Your program should start by printing instructions to the screen, explaining that the user should pick a number between 1 and 1000 and the computer will guess it in no more than 10 tries. It then starts making guesses, and after each guess it asks the user for feedback. The user should be instructed to enter -1 if the computer needs to guess a lower number, 0 if the computer guessed correctly, and 1 if the computer needs to guess a higher number. When the program guesses correctly, it should report how many guesses were required. If the user enters an invalid response, the instructions should be repeated and the user allowed to try again. You may assume that the user never gives a false answer. (Read the full assignment here)
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
Computer ProgrammingThis course is a full year. Students will be studying the basics of computer programming. The programming tool we will use is the popular and powerful language called Python (Python.org). Students will be exploring the fundamental logical concepts of programming that apply to any programming language.
Archives
April 2016
Categories |