Question

For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

For Python

debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n.

By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular.

def main():
# Local variable
number = 0

# Get number as input from the user.
number = int(input('How many numbers to display? '))

# Display the numbers.
print_num(number)

# The print_num function is a a recursive function
# that accepts an integer argument, n , and prints
# the numbers 1 up through n.
def print_num(n):
if n > 1:
print_num(n + 1)
print (n, sep=' ')

# Call the main function.
main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def main():
    # Local variable
    number = 0

    # Get number as input from the user.
    number = int(input('How many numbers to display? '))

    # Display the numbers.
    print_num(number)

# The print_num function is a a recursive function
# that accepts an integer argument, n , and prints
# the numbers 1 up through n.
def print_num(n):
    if n > 0:
        print_num(n - 1)
        print (n, sep=' ')

# Call the main function.
main()

Add a comment
Know the answer?
Add Answer to:
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...
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
  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise...

    C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise a number to a power. The function should accept two arguments, the number to be raised and the exponent. Assume that the exponent is a non-negative integer. String Reverser function that accepts a string object as its argument and prints the string in reverse order. Sum of Numbers this function accepts an integer argument and returns the sum of all the integers from 1...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Write a Python function isPrime(number) that determines if the integer argument number is prime or not....

    Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...

  • C++ 9) Write a recursive function printAll that takes an int num argument and prints all...

    C++ 9) Write a recursive function printAll that takes an int num argument and prints all the numbers in the range [num, 0]. The function returns nothing. e.g. printAll(5) prints 5, 4, 3, 2, 1, 0. Call your function in the main

  • Implement a Python function that prints integers from a to b. The main part of the...

    Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and...

    (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and return the result of the following function: f(N) = 1 + 1/2! + 1/3! + ...+1/N! Write a C program that reads an integer value. The program should call the function above and then print the result on the screen with two decimal point format (i.e. 12.34).

  • Below you will find a recursive function that computes a Fibonacci sequence (Links to an external...

    Below you will find a recursive function that computes a Fibonacci sequence (Links to an external site.).   # Python program to display the Fibonacci sequence up to n-th term using recursive functions def recur_fibo(n): """Recursive function to print Fibonacci sequence""" if n <= 1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) # Change this value for a different result nterms = 10 # uncomment to take input from the user #nterms = int(input("How many terms? ")) # check if the number...

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