Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Loopy Zebras In this quest, you get to play with looping. You will create a bunch of functions, each of which does something that requires

Loopy Zebras
In this quest, you get to play with looping. You will create a bunch of functions, each of which does something that requires you to iterate over a sequence of steps more than once.
Each of these functions is worth a varying number of points. It's up to you to find out how many points you can score by making the most progress you can.
As usual, I will give you template code you can copy and flesh out.
Important note
In miniquests where you have to calculate the value of some fractional quantity (ex and gp terms) you may not use the Math library methods (e.g. sqrt, pow, etc). If you do, you'll find that your results may be very slightly different from mine. They have to match exactly for you to pass the miniquests. There's the challenge.
Your first miniquest - Guess it
To get past this checkpoint you must correctly implement the following function in the template code:
bool play_game(int n);
When I invoke this method, I will supply it an integer parameter, n, which you must treat as a secret number.
Then you must give the user 6 chances to guess the number using the exact script below:
As soon as the function begins, print the following on the console to greet the user:
Welcome to my number guessing game
followed by exactly two blank newlines.
Recall that an AP is specified by two terms a and d. The first term is a, and the d is how much you add to each term to get the next term. So the first N terms of the above AP will be:
a,a+d,a+2d,***,a+(n-1)**d
Suppose, for example, that a=1,d=3, and n=5. Then this function should return the string 1,4,7,10,13
Page 4 of 8
Note some important things about the returned value: There are no newlines or spaces. Only commas separate the numbers. There is NO comma before the first number or after the last number. The format has to match exactly.
Your sixth miniquest - Terms of a GP
Copy and adapt the function in the previous mini-quest to turn it into a function that returns the terms of a geometric progression, rather than an arithmetic one. We're talking about changes to a couple of lines.
However, note that the parameter types are different. You should operate in double space to keep high precision (not in integer space).
Recall that a GP is specified by two terms a and r. The first term of the sequence is a, and the r is by how much multiply each term to get the next term. So the first N terms of the above AP will be:
Loopy Zebras
In this quest, you get to play with looping. You will create a bunch of functions, each of which does something that requires you to iterate over a sequence of steps more than once.
Each of these functions is worth a varying number of points. It's up to you to find out how many points you can score by making the most progress you can.
As usual, I will give you template code you can copy and flesh out.
Important note
In miniquests where you have to calculate the value of some fractional quantity (ex and gp terms) you may not use the Math library methods (e.g. sqrt, pow, etc). If you do, you'll find that your results may be very slightly different from mine. They have to match exactly for you to pass the miniquests. There's the challenge.
Your first miniquest - Guess it
To get past this checkpoint you must correctly implement the following function in the template code:
bool play_game(int n);
When I invoke this method, I will supply it an integer parameter, n, which you must treat as a secret number.
Then you must give the user 6 chances to guess the number using the exact script below:
As soon as the function begins, print the following on the console to greet the user:
Welcome to my number guessing game
followed by exactly two blank newlines.
Recall that an AP is specified by two terms a and d. The first term is a, and the d is how much you add to each term to get the next term. So the first N terms of the above AP will be:
a,a+d,a+2d,***,a+(n-1)**d
Suppose, for example, that a=1,d=3, and n=5. Then this function should return the string 1,4,7,10,13
Page 4 of 8
Note some important things about the returned value: There are no newlines or spaces. Only commas separate the numbers. There is NO comma before the first number or after the last number. The format has to match exactly.
Your sixth miniquest - Terms of a GP
Copy and adapt the function in the previ
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions