Knowee
Questions
Features
Study Tools

Single File Programming QuestionProblem StatementDevelop a program to simulate the countdown sequence for a historic rocket launch. Given a positive integer n representing the number of seconds left, the program should print a countdown sequence in the format "n-(n-1)-...-1". This countdown replicates the final moments before the liftoff of a significant space mission. Write a recursive function called countdown that takes n as input and prints the countdown sequence.Input format :The input consists of an integer n, representing the number of seconds left for the rocket launch.Output format :The output prints the countdown sequence in the format: "n-(n-1)-...-1".Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:5 ≤ n ≤ 100Sample test cases :Input 1 :5Output 1 :5-4-3-2-1Input 2 :13Output 2 :13-12-11-10-9-8-7-6-5-4-3-2-1Input 3 :100Output 3 :100-99-98-97-96-95-94-93-92-91-90-89-88-87-86-85-84-83-82-81-80-79-78-77-76-75-74-73-72-71-70-69-68-67-66-65-64-63-62-61-60-59-58-57-56-55-54-53-52-51-50-49-48-47-46-45-44-43-42-41-40-39-38-37-36-35-34-33-32-31-30-29-28-27-26-25-24-23-22-21-20-19-18-17-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Question

Single File Programming QuestionProblem StatementDevelop a program to simulate the countdown sequence for a historic rocket launch. Given a positive integer n representing the number of seconds left, the program should print a countdown sequence in the format "n-(n-1)-...-1". This countdown replicates the final moments before the liftoff of a significant space mission. Write a recursive function called countdown that takes n as input and prints the countdown sequence.Input format :The input consists of an integer n, representing the number of seconds left for the rocket launch.Output format :The output prints the countdown sequence in the format: "n-(n-1)-...-1".Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:5 ≤ n ≤ 100Sample test cases :Input 1 :5Output 1 :5-4-3-2-1Input 2 :13Output 2 :13-12-11-10-9-8-7-6-5-4-3-2-1Input 3 :100Output 3 :100-99-98-97-96-95-94-93-92-91-90-89-88-87-86-85-84-83-82-81-80-79-78-77-76-75-74-73-72-71-70-69-68-67-66-65-64-63-62-61-60-59-58-57-56-55-54-53-52-51-50-49-48-47-46-45-44-43-42-41-40-39-38-37-36-35-34-33-32-31-30-29-28-27-26-25-24-23-22-21-20-19-18-17-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for the problem:

def countdown(n):
    if n == 1:
        print(n, end="")
    else:
        print(str(n) + "-", end="")
        countdown(n-1)

n = int(input())
countdown(n)

This program works by defining a recursive function countdown that takes an integer n as input. If n is 1, it simply prints n. Otherwise, it prints n followed by a dash, and then calls itself with n-1 as the new input. This continues until n is 1, at which point the recursion stops. The end="" argument in the print function is used to prevent it from printing a newline after each number, so that the entire countdown sequence is printed on one line. The program takes the number of seconds left for the rocket launch as input from the user, and then calls the countdown function with this number to start the countdown.

This problem has been solved

Similar Questions

Single File Programming QuestionProblem StatementJessi wants to write a program where a recursive function, recursiveFunc, is called with an input integer n. Inside the function, a local variable m is initialized to 3 using the auto keyword. The program prints the value of m before and after each recursive call. The input integer n is obtained from the user in the main function.Input format :The input consists of an integer n.Output format :The output prints the value of the variable m before and after each recursive call from n to 0:The format for before call: "Before call(x): m" where x is the number of the particular call.The format for after call: "After return(x): m" where x is the number of the particular call.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ n ≤ 10Sample test cases :Input 1 :1Output 1 :Before call(1): 3Before call(0): 3After return(0): 3After return(1): 3Input 2 :5Output 2 :Before call(5): 3Before call(4): 3Before call(3): 3Before call(2): 3Before call(1): 3Before call(0): 3After return(0): 3After return(1): 3After return(2): 3After return(3): 3After return(4): 3After return(5): 3Input 3 :10Output 3 :Before call(10): 3Before call(9): 3Before call(8): 3Before call(7): 3Before call(6): 3Before call(5): 3Before call(4): 3Before call(3): 3Before call(2): 3Before call(1): 3Before call(0): 3After return(0): 3After return(1): 3After return(2): 3After return(3): 3After return(4): 3After return(5): 3After return(6): 3After return(7): 3After return(8): 3After return(9): 3After return(10): 3Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Single File Programming QuestionProblem StatementHelen is developing a program for a gaming application that involves generating a sequence of mystical numbers based on the Tribonacci series. She needs to implement a recursive function tribonacci to determine the Tribonacci numbers for various stages of the quest. Write a program to achieve her task.The Tribonacci series is a sequence of numbers defined as the sum of the three preceding terms. 0, 1, 1, 2, 4, 7, 13, and so on.Input format :The input consists of a positive integer n.Output format :The output displays the n terms in the Tribonacci series, separated by a space.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ n ≤ 20Sample test cases :Input 1 :2Output 1 :0 1 Input 2 :9Output 2 :0 1 1 2 4 7 13 24 44 Input 3 :18Output 3 :0 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 5768 10609 Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Single File Programming QuestionProblem StatementHelen is developing a program that analyzes numerical inputs. The program categorizes each input based on its value: a positive number elicits a specific message, a negative number prompts a different response, and inputting zero generates a unique message.Create a program that identifies the type of a number inputted. Ensure the program exits using a return statement after identifying the type of the number.Input format :The input consists of a single integer, N, which represents the number.Output format :The output displays one of the following:If the given number is positive, then display the statement "The number is positive."If the given number is negative, then display the statement "The number is negative."If the given number is zero, then display the statement "The number is zero."Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:-100 ≤ N ≤ 100Sample test cases :Input 1 :100Output 1 :The number is positive.Input 2 :-100Output 2 :The number is negative.Input 3 :0Output 3 :The number is zero.

Single File Programming QuestionProblem StatementPhilip is given the following expression: (++n) * (--m). Design a program for Philip that takes initial values for variables m and n, evaluates the expression, and prints the result. Ensure that the program handles pre-increment (++n) and pre-decrement (--m) operations correctly.Input format :The input consists of two space-separated integers representing the values of m and n.Output format :The output displays an integer representing the result of the given expression.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:10 ≤ m, n ≤ 500Sample test cases :Input 1 :10 12Output 1 :117Input 2 :485 500Output 2 :242484Input 3 :100 25Output 3 :2574

Single File Programming QuestionProblem StatementBuzzcraft, an event-organizing company, has seen steady growth in its workforce. The company has observed a unique growth pattern in the number of employees, represented by the series: 20, 60, 104, 152, 204, … Write a program that simulates Buzzcraft's employee growth that takes an integer N as input and outputs the series of the number of employees up to the Nth term using a for loop.Note: This question was asked in InfyTQ coding test.Input format :The input consists of an integer N.Output format :The output prints a single line of the series of integers till the Nth term of the given series, each separated by a space.Refer to sample input and output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 100Sample test cases :Input 1 :1Output 1 :20 Input 2 :100Output 2 :20 60 104 152 204 260 320 384 452 524 600 680 764 852 944 1040 1140 1244 1352 1464 1580 1700 1824 1952 2084 2220 2360 2504 2652 2804 2960 3120 3284 3452 3624 3800 3980 4164 4352 4544 4740 4940 5144 5352 5564 5780 6000 6224 6452 6684 6920 7160 7404 7652 7904 8160 8420 8684 8952 9224 9500 9780 10064 10352 10644 10940 11240 11544 11852 12164 12480 12800 13124 13452 13784 14120 14460 14804 15152 15504 15860 16220 16584 16952 17324 17700 18080 18464 18852 19244 19640 20040 20444 20852 21264 21680 22100 22524 22952 23384 Input 3 :5Output 3 :20 60 104 152 204

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.