Concept explainers
The population of town
Your program should utilize input validation loopsto allow the user to correct errors on input so that the program can continue processing. This program should have two input validation loops:
•one to verify that the population of town A is less than the population of town B
•one to verify that the population growth rate of town A is greater than the population growth rate of town B.
Here is the
Get the initial population of town A and town B.
While the initial population of town A > initial population of town B
Get the initial population of town A and town B
Get the growth rates of town A and town B.
While the growth rate of A < growth rate of B
Get the growth rate of town A and town B
To solve the problem, consider the populations of town A and town B from the initial year to the next year:
•populationA = populationA + populationA * growthRateA
•populationB = populationB + populationB * growthRateB
Set up a loop to compare the new population values to see if populationAis greater than or equal to populationB, if not, repeat the process until it is. Set up a counter inside the loop to determine the number of years it takesfor the populations to match.
C++
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- e input is: 3 the output is: heads heads tails For reproducibility needed for auto-grading, seed the program with a value of 1. In a real program, you would seed with the current time. In that case, every program's output would be different, which is what is desired but can't be auto-graded. Note: A common student mistake is to seed before each call to random.randint(). But seeding should only be done once, at the start of the program, after which random.randint() can be called any number of times. Your program must define and call the heads_or_tails() function that randomly picks 0 or 1 and returns "heads" or "tails". Assume the value 0 represents "heads" and 1 represents "tails". i have this: import random def heads_or_tails(n): i=0 while i<n: random.randint(0,1) if num==0: print('heads') else: print('tails') i = i + 1 if __name__ == '__main__': random.seed(1) number_of_flips = int(input()) heads_or_tails(number_of_flips) it…arrow_forwarduser if the guess is too high or too low or is correct. 3. Using nested for loops, right a program that displays a bar chart (using asterisks) for a number entered by the user. For example, if the user enters 4, the bar chart looks like this: 4: **** Do this five times total. Write a program tha ddiviarrow_forwardThis program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade earned in each test and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : : In test 1 the highest grade was 93% and the average was 89.2% In test 2........etc Your main method should be modular. Write a method that inputs the 5 names into an array (one dimensional), and returns this array to the main Write a method that inputs the 15 (integer) test grades into a (two-dimensional) array, and returns this array to the main Write a method that calculates the students averages and stores them in an array, and returns this array to the main Write a method that calculates the average grade for each test and stores them in an array, and returns this array to the main Write a method that determines the highest grade…arrow_forward
- Practices Flowgorithm programming for the followingarrow_forwardThe automatic soft-drinks vending machine (SVM) is free and self checking every 10 minutes. After receiving the cash, the SVM waits for the user to select the desired drink. After the user makes a choice, the SVM checks whether the amount of cash entered by the customer is enough to buy the drink. If it is enough, the selected drink will be output; otherwise, it will wait for the user to continue to invest in cash. If the user does not make up the cash within one minute, the cash will be returned. During the purchase process, if the user presses the "Cancel" button, the cash will be returned. Task: draw a state chart diagram for the SVM.arrow_forwardDesign a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Modularize the program. Present clear formatted code with comments. I need this coded in pseudocode, please.arrow_forward
- 9 am Input 3 5 7 ~ 00 2 Write a program that repeatedly gets integer input from the user until the value 99999 is entered. The program must then print the values the user entered alternating between odd and even values starting with the first odd value as in the examples below. The odd and even values must respectively be in the order they were entered but the overall output will not necessarily be in the order entered. 8 If more odd or even values were entered, the program should continue to print the remaining values after all other odd/even values have been printed in the order they were entered. Note: You must use Queues to solve this problem: an implementation of the Queue class is given - you do not need to provide your own. You will have the following methods available from the Queue class: Queue), enqueue(), .dequeue(), peek(), len(), and.is_empty(). Note: You must NOT access private data fields of the Queue class, you must NOT create any other built-in collections (e.g. lists,…arrow_forward3. The formula for determining compound interest is: A represents the amount to earn; P is the principle that is initially invested; r is the interest rate earned; n is the number of times the interest is compounded; and t is the number of time periods for the investment. Write a program that prompts the user to enter P, r, n and t. The program should output the amount earned on the investment. 4. Look up the Pythagorean theorem if you are not already familiar with it. Use the following formula to solve for c in the formula: c = √a2 + b2. Use the proper functions from the cmath header file. Be sure to output the result.larrow_forward26.Temperature Conversion Write a program which prompts the user for a Fahrenheit temperature, convert it to Celsius temperature, and print out the converted temperature. Hint: Celsius temperature (Fahrenheit temperature – 32) ÷ 1.8 - Sample input and output: Fahrenheit temperature: 60 Celsius temperature: 15.56arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education