Question

CHALLENGE ACTIVITY 6.4.2: Recursive function: Writing the recursive case. Write code to complete factorial_str()s recursive

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def factorial_str(fact_counter, fact_value):
    output_string = ''

    if fact_counter == 0:
        output_string += '1'
    elif fact_counter == 1:
        output_string += str(fact_counter) + ' = ' + str(fact_value)
    else:
        output_string += str(fact_counter) + ' * '
        next_counter = fact_counter - 1
        next_value = next_counter * fact_value
        output_string += factorial_str(next_counter,next_value)
    return output_string


user_val = int(input())
print('{}! = '.format(user_val),end="")
print(factorial_str(user_val,user_val))

Screenshot of the program :

Output :

Add a comment
Know the answer?
Add Answer to:
CHALLENGE ACTIVITY 6.4.2: Recursive function: Writing the recursive case. Write code to complete factorial_str()'s recursive case....
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
  • CHALLENGE ACTIVITY 13.1.2: Basic function call. Complete the function definition to output the hours given minutes....

    CHALLENGE ACTIVITY 13.1.2: Basic function call. Complete the function definition to output the hours given minutes. Output for sample program: 3.5 1 test passed All tests passed 1 #include <iostream> 2 using namespace std; 3 4 void OutputMinutesAsHours (double origMinutes) { 5 6 /* Your solution goes here */ 7 8} 9 10 int main() { 11 double minutes; 12 13 cin >> minutes; 14 15 OutputMinutesAsHours (minutes); // Will be run with 210.0, 3600.0, and 0.0. 16 cout <<...

  • This code is based on creating a recursive funciton. You cannot alter the code besides adding...

    This code is based on creating a recursive funciton. You cannot alter the code besides adding your solution in the particular area. Write code to complete PrintFactorial()'s recursive case. Sample output if userVal is 5: 5! = 5 * 4 * 3 * 2 * 1 = 120 #include void PrintFactorial(int factCounter, int factValue){    int nextCounter = 0;    int nextValue = 0;    if (factCounter == 0) {            // Base case: 0! = 1       printf("1\n");    }...

  • Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - dis...

    Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - displays the items in the cart ---------------------------------------------------------------------""" import os os.system('clear') print("\n\nCart Contents:") print("Your selected items:", cart) def catMenu(): #function that displays the category menu """catMenu function - displays the categories user picks from ---------------------------------------------------------------------""" import os os.system('clear') print(""" 1 - Books 2 - Electronics 3 - Clothing d - display cart contents x -...

  • This is for C program CHALLENGE ACTIVITY 6.5.1: Unit testing. Add two more statements to main0...

    This is for C program CHALLENGE ACTIVITY 6.5.1: Unit testing. Add two more statements to main0 to test inputs 3 and-1. Use print statements similar to the existing one (don't use assert) 1 #include <stdio.h> test 3 // Function returns origNum cubed 4 int CubeNum(int origNum) t 5 return origNum origNumorigNum; 6 b All tests passed 8 int main void) 10 printfC"Testing started\n"; printf("2: Expecting 8, got: %d\n", CubeNum(2)); 14 Your solution goes here 15 16 printfC Testing completed\n"; 17...

  • in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first...

    in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first three elements of array run Times. Follow each statement with a newline. Ex: If runTime = (800,775, 790, 805, 808) print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5 element array. See 'How to Use zyBooks". Also note: If the submitted code tries to access an invalid array...

  • Something is preventing this python code from running properly. Can you please go through it and...

    Something is preventing this python code from running properly. Can you please go through it and improve it so it can work. The specifications are below the code. Thanks list1=[] list2=[] def add_player(): d={} name=input("Enter name of the player:") d["name"]=name position=input ("Enter a position:") if position in Pos: d["position"]=position at_bats=int(input("Enter AB:")) d["at_bats"] = at_bats hits= int(input("Enter H:")) d["hits"] = hits d["AVG"]= hits/at_bats list1.append(d) def display(): if len(list1)==0: print("{:15} {:8} {:8} {:8} {:8}".format("Player", "Pos", "AB", "H", "AVG")) print("ORIGINAL TEAM") for x...

  • Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save...

    Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save the data Update the program so it reads the player data from a file when the program starts andwrites the player data to a file anytime the data is changed What needs to be updated: Specifications Use a CSV file to store the lineup. Store the functions for writing and reading the file of players in a separate module than the rest of the...

  • Please help me write a program flowchart! I have been struggling for quite some time, and...

    Please help me write a program flowchart! I have been struggling for quite some time, and mainly I need the answer. Thank you ! room Hef main(); #run order: date waitlist budget result numGuests = guests() weekDay = date() waitList = waitlist(weekDay) hotelBudget - budget() print("Day:, displayWeek (weekDay)) print("Budget: ", hotel Budget) result(waitList, numGuests, room(numGuests, hotelBudget)) def guests(): numGuests - while numGuests <=@ or numGuests > 8: try: numGuests = (int(input("Please enter number of guests:"))) if numGuests > 8: print("Maximum...

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • 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