Question

In: Computer Science

Please code in python or C++ Misty is fond of pokemons and likes to collect pokemon...

Please code in python or C++

Misty is fond of pokemons and likes to collect pokemon cards. She has P pokemon cards with her at present. She wants to have a particular number of cards on the Dth day. Her friend Ash is ready to help her to achieve the number. Ash will provide her N cards daily so that a day before the Dth day, she will have the required number of Pokemon cards.

Example:

Misty has cards with her, P = 5

D = 6

Ash will provide her with cards daily, N = 4

Ash provides pokemon cards:

Day 1 = 4

Day 2 = 4

Day 3 = 4

Day 4 = 4

Day 5 = 4

Total cards Ash provides = 4 + 4 + 4 + 4 + 4 = 20

Total number of pokemon cards Misty has on the Dth day = 5 + 20 = 25

Misty is busy with her tournament and wants to know the total number of pokemon cards she will have on Dth day. Can you tell her?


Input Format

The first line of input consists of the number of test cases, T

The only line of each test case consists of three space-separated integers, P, N and D.


Constraints

1<= T <=100

1<= D <=100000

0 <= P, N <=100000

Solutions

Expert Solution

We have, initial cards = P.

Number of days for which cards are given = (D-1), since no cards are given on the Dth day. (e.g. as in the example above, D = 6, but the cards are given out only for 5 days).

Cards given per day = N.

Then, total number of cards at the end of the Nth day: P + (D-1)*N

Python code for the above problem:

T = int(input())
while T: 
    P, D, N = input().split()
    P = int(P)
    D = int(D)
    N = int(N)
    totalcards = P + (D-1)*N 
    print(totalcards)
    T = T-1

We take the number of testcases as input, and then we use a while loop to take inputs for each testcase. We take P, D, N as space separated (default separator in the split() function is the space) values. Then, since they are positive integers, we convert them to integer inputs (since the default input type in python is a string). Once that is done, we use the formula derived above to calculate the total number of cards and we print it. We keep on iterating over each testcase and printing the values out.

Output:

You may also append the value of totalcards to a list for each testcase if so desired, but the output format was not specified in the question. The print() statement is the easiest method in this case.

(If you liked this answer, feel free to give it a thumbs up. Thank you so much!)


Related Solutions

Misty is fond of pokemons and likes to collect pokemon cards. She has P pokemon cards...
Misty is fond of pokemons and likes to collect pokemon cards. She has P pokemon cards with her at present. She wants to have a particular number of cards on the Dth day. Her friend Ash is ready to help her to achieve the number. Ash will provide her N cards daily so that a day before the Dth day, she will have the required number of Pokemon cards.
Misty is fond of pokemons and likes to collect pokemon cards. She has P pokemon cards...
Misty is fond of pokemons and likes to collect pokemon cards. She has P pokemon cards with her at present. She wants to have a particular number of cards on the Dth day. Her friend Ash is ready to help her to achieve the number. Ash will provide her N cards daily so that a day before the Dth day, she will have the required number of Pokemon cards.
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
I would like the following code in PYTHON please, there was a previous submission of this...
I would like the following code in PYTHON please, there was a previous submission of this question but I am trying to have the file save as a text file and not a json. Any help would be greatly appreciated. Create an application that does the following: The user will enter product codes and product numbers from the keyboard as strings. The product code must consist of four capital letters. The product number can only consist of numeric characters, but...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT