Question

In: Computer Science

Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below....

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

Solutions

Expert Solution

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)


Related Solutions

create a new Python 3 Jupyter Notebook.. Create one python code cell for the problem below....
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: 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...
Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below....
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. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page. Problem: Define a function with the following characteristics: The function's purpose will be calculating a factORRial...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook as "*assignment 2.08 - Your Name Here.ipynb*" (obviously, replace the "Your Name Here" part with your actual name). Create a single python cell to program the following specifications. Use what you've learned on this page to: 1. Find the index of "lmno" in the English alphabet using an appropriate instruction and store it in a variable. (hint: you'll need to define a string that...
Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one...
Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one required parameter: maxint, an integer that will serve as the upper bound of the loop Following the example on the Python tutorial: https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming Our implementation will have a few changes: While you will use a while loop to make a Fibonacci sequence, the upper bound of the sequence will be your maxint parameter. Store the results into a list and append each new generated...
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a...
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a penny, two a penny, hot cross buns.” Submitted files: (1) Source code (adding comments); (2) Supporting document for code comments
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0 Please show the code clearly.
Write a python programme in a Jupyter notebook which asks the user to input the number...
Write a python programme in a Jupyter notebook which asks the user to input the number of radioactive nuclei in a sample, the number at a later time, and the elapsed time. The programme should calculate and display the decay constant and the half-life. The decay is described by the equations: ? = ? ?−?? ?0 ?1/2 = ln (2) . Test your programme a sample that contains 4.00x108 nuclei initially and 1.57x107 nuclei after 150 seconds. SO THEREFORE A...
Create individual python code cells for each of the three problems below. In each code cell,...
Create individual python code cells for each of the three problems below. In each code cell, use any additional variables and comments as needed to program a solution to the corresponding problem. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page . 1. a. Cell Number 1 * Recreate the same list of dictionaries you used during assignment 2.09. (Scroll down to see assignment 2.09 instructions) * Create another variable and...
Create individual python code cells for each of the three problems below. In each code cell,...
Create individual python code cells for each of the three problems below. In each code cell, use any additional variables and comments as needed to program a solution to the corresponding problem. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page . 1. a. Cell Number 1 * Recreate the same list of dictionaries you used during assignment 2.09. (Scroll down to see assignment 2.09 instructions) * Create another variable and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT