Question: please help me pass this hidden input... OK, time now to rewrite a for loop as a while loop. Mr Frodo is having second thoughts


OK, time now to rewrite a for loop as a while loop. Mr Frodo is having second thoughts about the trip to Mordor. Being both a superstitious little chap and a Dungeons and Dragons fan, he carries a 20-sided die wherever he goes. He decides that he will roll the die a fixed number of times, and if his favourite number comes up, he will go to Mordor, and if not, he will return to the Shire. We will simulate the 20-sided die through the use of the randint function from the random library (a topic that we will cover properly in Worksheet 13; for now, just accept that from random import randint gives you access to the function, which returns a random integer between the values of the first and secod arguments, inclusive). Given the provided function luck_tester (lucky number, max_rolls, die_size), which takes as arguments: (1) a lucky number lucky_number (3 in Mr Frodo's case: the number of trolls his uncle encountered in the Trollshaws); (2) the maximum number of die rolls max_rolls; and (3) the die size die_size (in terms of the number of sides the die has; 20 in Mr Frodo's case); all can be assumed to be integers. The function should return a string, of value depending on whether the lucky number comes up in the provided number of rolls of the die or not; the precise strings are provided in the original code. Note that rewritten function should behave identically to the of die rolls max_rolls; and (3) the die size die_size (in terms of the number of sides the die has; 20 in Mr Frodo's case); all can be assumed to be integers. The function should return a string, of value depending on whether the lucky number comes up in the provided number of rolls of the die or not; the precise strings are provided in the original code. Note that rewritten function should behave identically to the original, and the only changes you should make are to the for loop and associated variables, to rewrite it as a while loop. Submissions which don't do this will be rejected, so be sure to follow the requirements of the problem carefully! >>> luck_tester (42, 10, 20) Back to the Shire!' Dummy Variables You may have noticed the use of the underscore at the start of the variable name in the original for loop. This is a common way of indicating that the variable isn't actually referred to anywhere in the code, and is hence a "dummy" variable. There needs to be a variable there, as part of the syntax of the for construct, but we actually don't care about the value of the variable. 4 1 from random import randint 2 def luck_tester (Lucky number, max_rolls, die_size): 3 while max_rolls >e: max_rolls -= 1 if lucky number == randint(1, die_size): 6 return "Proceed to the Mordor!" 7 return "Back to the Shire!" 5 8 9 10 11. if __name__ == "__main__": print("Lucky Number: () | Max Rolls: 6 | Die Size: ".format(2, 10, 20 print(luck_tester(2, 10, 20)) 12 13 14 Submissions Output #2 Not yet! Failed a test (3 tests passed). 3 hours ago Current Checking that your submission does not use forbidden code constructs. Testing the example from the problem. Testing a hidden input. X Testing a hidden input
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
