Question

Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not...

Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working.

  • Describe each possibility in your own words.
  • Define "precondition" and "postcondition" as part of your description.
  • Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Precondition: n >= 0
Postcondition: The factorial of value (n) is returned
'''
def factorial(n):
    if(n < 0) :
        print('the precodition is violated')
        return

    space = ' ' * (4 * n)
    print(space, 'factorial', n)
    if n == 0:
        print(space, 'returning 1')
        return 1
    else:
        recurse = factorial(n-1)
        result = n * recurse
        print(space, 'returning', result)
        return result

factorial(5)
Add a comment
Know the answer?
Add Answer to:
Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file...

    Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following: How to format each dictionary item as a text string in the input file. How to covert each input string into a dictionary item. How to format each item of your inverted dictionary as a text string in the output file. Create an input file with your original...

  • Consider making a function (mini program to complete a specific task) for each of the scenarios...

    Consider making a function (mini program to complete a specific task) for each of the scenarios below. State what the purpose of the function is in your own words, specify input that is needed by the function, what output is expected from the functions, and the step by step process that will obtain the output from the input (the algorithm). In addition to these 4 items also specify test data that can be used for each problem. Remember to describe...

  • C language huffman This exercise will familiarize you with linked lists, which you will need for...

    C language huffman This exercise will familiarize you with linked lists, which you will need for a subsequent programming Getting Started assignment Overview Requirements Getting Started Submit Start by getting the files. Type 264get hw13 and then cd hw13 from bash. Pre-tester You will get the following files: Q&A Updates 1. huffman.h: An empty header file, you have to define your own functions in this homework. 2. huffman.c: An empty c file, you have to define your own functions in...

  • Name: ID NO: Section: 1. Assume that you have three sinusoidal signals and the parameters of...

    Name: ID NO: Section: 1. Assume that you have three sinusoidal signals and the parameters of each one of them is given below Amplitude is 3. cyclic frequency is 50Hz and phase shift is - Amplitude is 4, radian frequency is 40 and phase shift is Amplitude is 6, period is 0.05s, and phase shiftis- Write MATLAB code for the following Assume that the time interval is. Generate each signal Plot the above three signals in the same figure window...

  • For this program, you will be working with data from the NASA website which lists Near...

    For this program, you will be working with data from the NASA website which lists Near Earth Objects detected by the JPL Sentry System. You are given a text file listing the designation and impact probability (with Earth, generally within the next 100 years) of 585 Near Earth Objects. Your job will be to sort these objects by their impact probabilities. Input File Format The input file contains 585 records. Each record is on a separate line. Each line contains...

  • Please go to the Practice Exercises (at the end of Chapter 3 in your text on...

    Please go to the Practice Exercises (at the end of Chapter 3 in your text on page 129) and do Exercise E 3.14 which asks you to compute and print the current season of the year depending on the month and day (input as integers). Be sure to review Java boolean operators, multi-way IF-ELSE statements, Switch statements, and String comparison methods before implementing your Java code. The algorithm for this program has been written for you and is included in...

  • In Python Question 3 (13 points): Purpose: To practice your ability to modify lists and compute...

    In Python Question 3 (13 points): Purpose: To practice your ability to modify lists and compute with lists of lists Degree of Difficulty: Moderate For this question, you are given some population estimates, by age group, from Statistics Canada for some provinces. Starter File a5q3 starter.py is a file that contains a list of lists, to which the variable Pop-data refers, which represents 2020 population numbers. The first item in Pop_data is a list whose first item is the string...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

  • PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In t...

    c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT