In: Computer Science
Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below. Use any additional variables and comments as needed to program a solution to the corresponding problem. All functions should be defined at the top of the code in alphabetical order.
*Problem:* 1. Define a function with the following characteristics: * The function's purpose will be checking that a number matches another, so it should be named appropriately. * It must accept one parameter, which is the number it will be checking. Name this parameter appropriately. * It must have an appropriate docstring. * There needs to be a variable defined within the program that is the integer value of ((your birth month prepended to your birth year) mod 555). So if your birthday is October 1925, this variable would be (`101925 % 555`). It is the number the argument will be compared to, so name it appropriately. * If the numbers match, the function should return `True`, otherwise `False`.
2. Define a different function with the following characteristics: * This function will be trying to guess a passcode, so it should be named appropriately. * It must accept two parameters, both with default values. * The first parameter will be for the smallest number to check and its default value will be `0`. * The second parameter will be for the largest number to check and its default value will be `100`. * The function must have an appropriate docstring. * Create a variable to hold the correct passcode. You won't know the value yet, so define it as `None`. * Build a list of all of the numbers from the smallest to the largest (it must include the largest number in the list). *Hint: Use the `range()` function with the first argument as the smallest number and the second argument as the largest value plus `1`.* * Loop through the list and for each iteration of the loop, do the following: * Call the function described in step 1 with the current list item as the argument and assign its return value to a variable. * If the function above returns `True`, store the current list item in the correct passcode variable and break out of the loop. * Return the correct passcode.
3. In your main code section, call the function defined in step 2 and store its return value in a variable named "`passcode`". You'll use the default argument value for the smallest number, so leave it out of the call. However, for the largest number, you need to pass in `555` as the argument. 4. Print out the correct passcode in a format string with a friendly (or funny) message.
**Rubric:** * Adequate readability, comments, etc.
* Uses docstrings for methods * Calls checker function using default argument for the first parameter
* Calls checker function overriding argument for second parameter * Has a method to check against mod value
* Uses mod correctly * Has a method to loop through range * Uses default argments for parameters
* Range is defined using second parameter plus one
* Break out of loop when value is found
* Store in variable named passcode
* Uses a format string to print
* Has a main code section
def checkPasscode(guess):
'''
this function cheks whether a given number is the passcode
input:guess-> the number which will be checked for being
passcode
'''
birthday=101925
return guess==(birthday%555)
def guessPasscode(smallestGuess=0,largestGuess=100):
'''
function that checks all the number in a given range for being
passcode
'''
correct=None
for i in range(smallestGuess,largestGuess+1):
check=checkPasscode(i)
if check:
correct=i
break
return correct
passcode=guessPasscode(largestGuess=555)
print('The passcode found after guessing is',passcode)