Question: python is the programming language Lab 02: locane Powder Overview Man in Black: All right. Where is the poison? The battle of wits has begun.

 python is the programming language Lab 02: locane Powder Overview Man

in Black: All right. Where is the poison? The battle of wits

has begun. It ends when you decide and we both drink, and

find out who is right... and who is dead. The line above

python is the programming language

Lab 02: locane Powder Overview Man in Black: All right. Where is the poison? The battle of wits has begun. It ends when you decide and we both drink, and find out who is right... and who is dead. The line above is from the perennial favorite 1980s movie adaptation of William Goldman's The Princess Bride, wherein a mysterious hero sits down to a battle of wits with a villainous Sicilian kidnapper. The setup: two cups positioned between the two, one of which (purportedly) contains a colorless, odorless, lethal poison (viz., iocane powder). After a guess is made as to which cup contains the poison, both drink, and the winner is the one left standing For this machine problem you will write a program that simulates multiple rounds of this battle of wits, allowing the player to repeatedly guess which cup is poisoned. The computer will place the poison before the player guesses, and will reveal who is right... and who is dead, afterwards. At the outset, the computer will always place the poison in cup 2 before letting the player guess, but after enough guesses have been entered the computer will start to place the poison based on the pattern of previous guesses so as to outsmart the player Here's a sample game session (note how the silly player keeps alternating guesses, and that the computer catches on to this fact after a while): Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 1 times, and I drank the po ison 0 times Where is the iocane powder: my cup (1) or yours (2)? 2 Good guess! Ack! I drank the poison ! You died 1 times, and I drank the po ison 1 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 2 times, and I drank the po ison 1 times Where is the iocane powder: my cup (1) or yours (2)? 2 Good guess! Ack! I drank the poison ! You died 2 times, and I drank the po ison 2 times Where is the iocane powder : my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 3 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 2 Wrong! Ha! Never bet against a Sicil ian! You died 4 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 5 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 2 Wrong! Ha! Never bet against a Sicil ian! You died 6 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 7 times, and I drank the po ison 2 times Implementation To keep track of the pattern of previous guesses, you will use a dictionary that maps a pattern (of fixed length) to a list of counts for the subsequent guess. For instance, imagine that the computer observes the player continuing to alternate quesses across ten separate attempts, like so: '1,2,1,2,'1, 2', '1,2,'1','2'. If we are using a pattern detection length of three. then after the fourth guess we can create an entry in our dictionary that maps the key '121' to the list [0, 1, where the second value (1) in the list indicates that the player guessed 2 following the sequence '1, 2, '1. After the fifth guess, we create the entry '212' [1,0], and after the sixth guess we update the value for "121' to [0, 2] (since the user guesses 2' again, after the sequence 1, 2. '1'). Once the player enters a series of guesses that matches a previously seen pattern, the computer should place the poison in the cup that the player is least likely to guess next. When the player enters the next guess, the dictionary should be updated to reflect the actual guess. This means that if the computer has yet to see a given pattern of guesses, or when the counts are tied, it will have to place the poison "blindly -- your implementation should simply place the poison furthest away from itself should simply place the poison furthest away from itself (cup 2) record_guess The first function you are to complete is record_guess. It will take the following arguments: a dictionary to update (possibly containing previously recorded pattern - list mappings) a pattern string a guess -- which is either '1' or '2'. If necessary, the function will create a new entry for the pattern (if one doesn't already exist), then record the updated count for the guess. Since the dictionary is updated in place (i.e., mutated), the function will not return anything. Complete the function below, checking your implementation with the test cases that follow when you're ready. Note that in the future, the bulk of the description for functions we ask you to implement will simply be placed in the functions' docstrings, as below. Hints: the int function can be used to convert strings to integers, and you might find the dictionary's setdefault method useful. Lab 02: locane Powder Overview Man in Black: All right. Where is the poison? The battle of wits has begun. It ends when you decide and we both drink, and find out who is right... and who is dead. The line above is from the perennial favorite 1980s movie adaptation of William Goldman's The Princess Bride, wherein a mysterious hero sits down to a battle of wits with a villainous Sicilian kidnapper. The setup: two cups positioned between the two, one of which (purportedly) contains a colorless, odorless, lethal poison (viz., iocane powder). After a guess is made as to which cup contains the poison, both drink, and the winner is the one left standing For this machine problem you will write a program that simulates multiple rounds of this battle of wits, allowing the player to repeatedly guess which cup is poisoned. The computer will place the poison before the player guesses, and will reveal who is right... and who is dead, afterwards. At the outset, the computer will always place the poison in cup 2 before letting the player guess, but after enough guesses have been entered the computer will start to place the poison based on the pattern of previous guesses so as to outsmart the player Here's a sample game session (note how the silly player keeps alternating guesses, and that the computer catches on to this fact after a while): Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 1 times, and I drank the po ison 0 times Where is the iocane powder: my cup (1) or yours (2)? 2 Good guess! Ack! I drank the poison ! You died 1 times, and I drank the po ison 1 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 2 times, and I drank the po ison 1 times Where is the iocane powder: my cup (1) or yours (2)? 2 Good guess! Ack! I drank the poison ! You died 2 times, and I drank the po ison 2 times Where is the iocane powder : my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 3 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 2 Wrong! Ha! Never bet against a Sicil ian! You died 4 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 5 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 2 Wrong! Ha! Never bet against a Sicil ian! You died 6 times, and I drank the po ison 2 times Where is the iocane powder: my cup (1) or yours (2)? 1 Wrong! Ha! Never bet against a Sicil ian! You died 7 times, and I drank the po ison 2 times Implementation To keep track of the pattern of previous guesses, you will use a dictionary that maps a pattern (of fixed length) to a list of counts for the subsequent guess. For instance, imagine that the computer observes the player continuing to alternate quesses across ten separate attempts, like so: '1,2,1,2,'1, 2', '1,2,'1','2'. If we are using a pattern detection length of three. then after the fourth guess we can create an entry in our dictionary that maps the key '121' to the list [0, 1, where the second value (1) in the list indicates that the player guessed 2 following the sequence '1, 2, '1. After the fifth guess, we create the entry '212' [1,0], and after the sixth guess we update the value for "121' to [0, 2] (since the user guesses 2' again, after the sequence 1, 2. '1'). Once the player enters a series of guesses that matches a previously seen pattern, the computer should place the poison in the cup that the player is least likely to guess next. When the player enters the next guess, the dictionary should be updated to reflect the actual guess. This means that if the computer has yet to see a given pattern of guesses, or when the counts are tied, it will have to place the poison "blindly -- your implementation should simply place the poison furthest away from itself should simply place the poison furthest away from itself (cup 2) record_guess The first function you are to complete is record_guess. It will take the following arguments: a dictionary to update (possibly containing previously recorded pattern - list mappings) a pattern string a guess -- which is either '1' or '2'. If necessary, the function will create a new entry for the pattern (if one doesn't already exist), then record the updated count for the guess. Since the dictionary is updated in place (i.e., mutated), the function will not return anything. Complete the function below, checking your implementation with the test cases that follow when you're ready. Note that in the future, the bulk of the description for functions we ask you to implement will simply be placed in the functions' docstrings, as below. Hints: the int function can be used to convert strings to integers, and you might find the dictionary's setdefault method useful

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!