An Algorithm for Quests
An algorithm is a set of specific steps or instructions for solving a problem. For example there are algorithms to sort numbers, compute mathematical results and render images.
Sir Galwin has some advice for Ann.
Follow the established Algorithm for quests and you'll be alright. "If you have one or more leads, then you follow the best one. Otherwise, if you don't have any leads, you travel to where you can find more information. Break any ties by flipping a coin" Sir Galwin thinks of this as more of a 'heuristic'. What does 'heuristic' mean? |
Examples of Algorithms
Algorithm to find the largest number
We will make this algorithm work in Python. Here's what we'll need:
|
Hints:
Set up your variables by giving them a name and setting them to 1. eg: currentnumber = 1 Create a loop using while. Use the 'not equal to' symbol != to check for 0 Use raw_input() to get keyboard input. Don't forget a prompt for the user. raw_input() will give you text rather than a number. Convert it using the int() function, eg: currentnumber = int(currentnumber) Compare numbers with the greater than > or less than < symbols. Use an if statement here |