Question

Write a new recursive function countup that expects a negative argument and counts “up” from that...

Write a new recursive function countup that expects a negative argument and counts “up” from that number. Output from running the function should look something like this:

>>> countup(-3)
-3
-2
-1
Blastoff!

I need a script that runs and I can see it and learn why it is working with #comments.

The subject is writing a countup script to blastoff in computer science.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

File Edit Selection View Go Run Terminal Help Rough 1 2 go 4 C Rough.c et rough.cpp Rough.py X C: > Users > shiva > OneDrive

# Function definition with argument value of 'n'

def countup(n):

# Check if 'n' is negative

   if(n<0):

# If so, print the value of 'n'

       print(n)

# Increment value of 'n'

       n+=1

# Call the countup function again with the new value of 'n'

       countup(n)

# If 'n' is not negative

   else:

# Print 'Blastoff!'

       print("Blastoff!")

# Call the function with an argument value

countup(-3)

#SAMPLE OUTPUT

C:\Users\shiva OneDrive \Desktop\CSE Rough>python rough.py -3 -2 -1 Blastoff!

Add a comment
Know the answer?
Add Answer to:
Write a new recursive function countup that expects a negative argument and counts “up” from that...
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
  • a) You must write a recursive function that takes something of the form: ([(Int, Int, Int),...

    a) You must write a recursive function that takes something of the form: ([(Int, Int, Int), Int, Int) as an argument and returns something of the form: LE(Int, Int, Int)]] which should be interpreted as a list of lists of 3-tuples of RGB values. You may use helper functions if you wish, but your solution must be recursive. You must document the name of your function at the beginning of your code using a comment like -- foo :: ([(Int,...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • Exercise 4 – Passing an argument to a new thread and reporting on execution times================...

    Exercise 4 – Passing an argument to a new thread and reporting on execution times===================================================================== Here are some miscellaneous items on threads and resource usage times. This is a very short exercise to learn how to pass an argument to a thread’s start function. Write a program called threadArgA.c that simply does the following: Pass a simple integer to a thread’s start function at thread creation time. ii) The thread function will assign this argument as variable int i (just...

  • 8. (4 pts + 2Xc) Write a bash shell script called 08-numMajors that will do the following i. Read data from a class enrollment file that will be specified on the command line ii. If the file does no...

    8. (4 pts + 2Xc) Write a bash shell script called 08-numMajors that will do the following i. Read data from a class enrollment file that will be specified on the command line ii. If the file does not exist, is a directory, or there are more or less than one parameters provided, display an appropriate error/usage message and exit gracefully Display the number of a specified major who are taking a given class iii. The following is a sample...

  • Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to...

    Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to calculate the Fibonacci Function 1.) Use a recursive function called fib() to calculate the Fibonacci Function for the following values for the variable n. int n = 10; int n = 20; int n = 30; int n = 40; int n = 45; int n = 46; 2.) In addition to calculating and displaying the results, use a "timer" to see how long...

  • in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file...

    in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • Part 1 The function 'vbrf' (for very bad recursive function) is defined as follows: vbrf(0) =...

    Part 1 The function 'vbrf' (for very bad recursive function) is defined as follows: vbrf(0) = 2 vbrf(1) = 3 vbrf(2) = 4 vbrf(3) = 5 vbrf(n) = vbrf(n-1) - vbrf(n-2) + 3*vbrf(n-3) - 2*vbrf(n-4) if n > 3 Your job for this problem is to implement the function vbrf as a method in Java. Then write a program that uses this method to compute the function for various values of the argument and time how long it takes to...

  • You will implement and test several short recursive methods below. With the proper use of recursi...

    this can be done in one class or two separate classes,in java thanks! You will implement and test several short recursive methods below. With the proper use of recursion, none of these methods should require more than a dozen lines of code. Test all these in the same class. Keep adding methods and testing until all are working 5. A Fractal Pattern Examine this pattern of stars and blanks, and write a recursive method that can generate patterns such as...

  • python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a...

    python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...

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