Question

Starting out with Python 4th edition I need help with while loops I can't even get...

Starting out with Python 4th edition

I need help with while loops I can't even get one started correctly.

Write a program a program that predicts the approximate size of a population of organisms.

Problem 4.13 – population

Use a while loop; there are no text boxes, just regular input statements

Enter number of organisms: 2

Enter average daily increase: 30

Enter number of days to multiply: 10

DAY       APPROXIMATE POPULATION

-------------------------------------------------

1            2

2            2.600

3            3.380

4            4.394

5            5.712

6            7.426

7            9.654

8            12.550

9            16.315

10         21.209

starting_number = int(input('Enter the starting number of organisms: '))
daily_increase = int(input('Enter the average daily population increase (as a percentage): '))
days = int(input('Enter the number of days to multiply: '))

print('Day', '\t', 'Approximate Population')
print('------------------------------------')
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer..

CODE:

starting_number = int(input('Enter the starting number of organisms: '))
daily_increase = int(input('Enter the average daily population increase (as a percentage): '))
days = int(input('Enter the number of days to multiply: '))

print('Day', '\t', 'Approximate Population')
print('------------------------------------')
i=1
print('{0} \t {1}'.format(i,starting_number))#for printing first line it doesn't have trailing zeros 2.000
i+=1#increment i
while(i<days+1):#iterate through the days
starting_number+=starting_number*daily_increase/100#calculate daily increment
print('{0} \t {1:.3f}'.format(i,starting_number))#print result
i+=1
  
CODE Snapshot:

OUTPUT:

If you have any doubts please COMMENT..

If you understand the answer please give THUMBS UP....

Add a comment
Know the answer?
Add Answer to:
Starting out with Python 4th edition I need help with while loops I can't even get...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that will predict the size of a population of organisms. The program should...

    Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to display the size of the population for each...

  • Write a program that will predict the size of a population of organisms. The program should ask t...

    Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. A loop should display the size of the population for each day. Input Validation: Do not accept a number less than 2 for the starting size of the population. "The starting number of organisms must be at least 2."...

  • 5.11: Population Write a program that will predict the size of a population of organisms. The...

    5.11: Population Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage, expressed as a fraction in decimal form: for example 0.052 would mean a 5.2% increase each day), and the number of days they will multiply. A loop should display the size of the population for each day. Input Validation.Do not accept a number less than...

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Starting out with Python 4th edition I need help I followed a tutorial and have messed...

    Starting out with Python 4th edition I need help I followed a tutorial and have messed up also how does one include IOError and IndexError exception handling? I'm getting errors: Traceback (most recent call last): File, line 42, in <module> main() File , line 37, in main winning_times = years_won(user_winning_team_name, winning_teams_list) File , line 17, in years_won for winning_team_Index in range(len(list_of_teams)): TypeError: object of type '_io.TextIOWrapper' has no len() Write program champions.py to solve problem 7.10. Include IOError and IndexError...

  • #Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function...

    #Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function named roll that #accepts an integer argument number_of_throws. The #function should generate and return a sorted #list of number_of_throws random numbers between #1 and 6. The program should prompt the user to #enter a positive integer that is sent to the function, #and then print the returned list. How would you do this?

  • Python Programming 4th Edition: Need help writing this program below. I get an error message that...

    Python Programming 4th Edition: Need help writing this program below. I get an error message that says that name is not defined when running the program below. My solution: def main(): filename = "text.txt" contents=f.read() upper_count=0 lower_count=0 digit_count=0 space_count=0 for i in contents: if i.isupper(): upper_count+=1 elif i.islower(): lower_count+=1 elif i.isdigit(): digit_count+=1 elif i.isspace(): space_count+=1 print("Upper case count in the file is",upper_count) print("Lower case count in the file is",lower_count) print("Digit count in the file is",digit_count) print("Space_count in the file is",space_count)...

  • Need help with implementing a While, Do-while and for loops in a program. UML: - scnr...

    Need help with implementing a While, Do-while and for loops in a program. UML: - scnr : Scanner - rows : int - MAX_ASCII : int ------------------------------------------------------------------------------- + CharacterTables() : + CharacterTables(rows : int) : - getStartingValue() : int -displayTable(startValue : int) : void - userContinue() : boolean + main(args : String[]) : void In Section 5.10 we saw that there is a close relationship between char and int. Variables of type char store numbers. (Actually, variables of all types...

  • Hi. Please help me solve this in python using only while loops, if statements. Can't use...

    Hi. Please help me solve this in python using only while loops, if statements. Can't use for loops and lists. In this programming assignment, you will be writing a program that prints out several shapes via text. In this PA, you will be required to use functions and parameters. This is both to reduce redundancy and to make your code clean and well-structured. Name your program shaper.py Your program should have the capability to print out three different shapes: An...

  • Need help creating a basic java string program using nested if/else, return loops or while loops...

    Need help creating a basic java string program using nested if/else, return loops or while loops or charAt methods while returning information using a console, Please leave notes as to compare my program and see where I went wrong or could've used a different method. secondsAfterMidnight Input: String that represents time of day Returns: integer number of seconds after midnight (return -1 if String is not valid time of day) General time of day format HH:MM:SS(AM/PM) These are examples where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT