Knowee
Questions
Features
Study Tools

Problem StatementCreate a program to assist a fitness tracker. Input the user's current step count (n). If n is even, print 'M' for meeting the daily goal, and set the next day's goal to half of nIf n is odd, print 'A' for almost reaching the goal and set the goal to n minus 1. Repeat this until n becomes 1. Write a recursive function called fitness_tracker that performs the above adjustments and prints the achievement status.For example: If n=5:For n = 5, it prints 'A'. Since n is odd it subtracts 1 to get n = 4.For n = 4, it prints 'M'. Since n is even it halves n to get n = 2.For n = 2, it prints 'M'. Since n is even it halves to reach n = 1, completing the process.So the output is "AMM".Input format :The input consists of an integer n, representing the user's current step count.Output format :The output prints 'M' or 'A' based on meeting or almost reaching the daily goal, adjust and display the next day's goal, until 'n' becomes 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 ≤ 50Sample test cases :Input 1 :5Output 1 :AMMInput 2 :13Output 2 :AMMAMInput 3 :50Output 3 :MAMMMAM

Question

Problem StatementCreate a program to assist a fitness tracker. Input the user's current step count (n). If n is even, print 'M' for meeting the daily goal, and set the next day's goal to half of nIf n is odd, print 'A' for almost reaching the goal and set the goal to n minus 1. Repeat this until n becomes 1. Write a recursive function called fitness_tracker that performs the above adjustments and prints the achievement status.For example: If n=5:For n = 5, it prints 'A'. Since n is odd it subtracts 1 to get n = 4.For n = 4, it prints 'M'. Since n is even it halves n to get n = 2.For n = 2, it prints 'M'. Since n is even it halves to reach n = 1, completing the process.So the output is "AMM".Input format :The input consists of an integer n, representing the user's current step count.Output format :The output prints 'M' or 'A' based on meeting or almost reaching the daily goal, adjust and display the next day's goal, until 'n' becomes 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 ≤ 50Sample test cases :Input 1 :5Output 1 :AMMInput 2 :13Output 2 :AMMAMInput 3 :50Output 3 :MAMMMAM

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

Solution

Sure, here is a Python solution for the problem:

def fitness_tracker(n):
    if n == 1:
        return ''
    elif n % 2 == 0:
        return 'M' + fitness_tracker(n // 2)
    else:
        return 'A' + fitness_tracker(n - 1)

print(fitness_tracker(5))  # Output: AMM
print(fitness_tracker(13))  # Output: AMMAM
print(fitness_tracker(50))  # Output: MAMMMAM

This program works by defining a recursive function fitness_tracker

This problem has been solved

Similar Questions

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.

ingle File Programming QuestionProblem StatementJustin needs a program to generate and analyze the Hailstone Sequence for a specific positive number up to 1. Hailstone Sequences follow these rules: If a number is even, divide it by 2. If a number is odd, multiply it by 3 and add 1.Help Justin by writing a program using a function to calculate the Hailstone sequence.For example: If the input number is 13, the calculations are as follows:13 (Odd): 3 * 13 + 1 = 4040 (Even): 40 / 2 = 2020 (Even): 20 / 2 = 1010 (Even): 10 / 2 = 55 (Odd): 3 * 5 + 1 = 1616 (Even): 16 / 2 = 88 (Even): 8 / 2 = 44 (Even): 4 / 2 = 22 (Even): 2 / 2 = 1Hence the sequence is 13 40 20 10 5 16 8 4 2 1 and the length of the sequence is 10. Note: This question helps in clearing technical coding tests for service-based companies.Input format :The input consists of a positive integer n, representing the starting number for the Hailstone Sequence.Output format :The first line displays the Hailstone Sequence starting from n up to 1, separated by a space.The second line displays "The length of the sequence is X." where X is the length of the generated sequence.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:2 ≤ n ≤ 300Sample test cases :Input 1 :13Output 1 :13 40 20 10 5 16 8 4 2 1 The length of the sequence is 10.Input 2 :300Output 2 :300 150 75 226 113 340 170 85 256 128 64 32 16 8 4 2 1 The length of the sequence is 17.Input 3 :2Output 3 :2 1 The length of the sequence is 2.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.Marks : 10Negative Marks : 0

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

Problem 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 27

Problem StatementCreate a program that generates and prints the Fibonacci series up to a specified number 'N'. The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding numbers, starting with 0 and 1. Your program should take an integer input 'N' and display the Fibonacci series up to the Nth term using a while loop.Fibonacci series: 0, 1, 1, 2, 3, 5, 8,... Note: This question is one of the most asked questions in placements.Input format :The input consists of a positive integer N.Output format :The output displays the Fibonacci series up to the Nth term separated by space.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 20The Fibonacci series starts from 0.Sample test cases :Input 1 :7Output 1 :0 1 1 2 3 5 8 Input 2 :1Output 2 :0 Input 3 :20Output 3 :0 1 1 2 3 5 8 13 21 34 55

1/1

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.