Python

profilebunny9095
Python.docx

1. 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 for loop to display the size of the population for each day. So for the previous example, the output should look like:

Day Organisms

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

1 2.0

2 3.0

3 4.5

4 6.75

5 10.125

6 15.1875

7 22.78125

Input validation: Do not accept a number less than 2 for the staring size of the population. Do not accept a negative number for average percent daily population increase. Do not accept a number less than 1 for the number of days they will multiply.

2. Write a program that takes user entered lines from the keyboard and stores them in an array. When the user enters "quit", the program prints out all the lines sorted (i.e. a line starting with a_n_ _“A_b_…” _w_o_u_l_d_ _p_r_i_n_t_ _o_u_t_ _b_e_f_o_r_e_ _o_n_e_ _s_t_a_r_t_i_n_g_ _w_i_t_h_ _“A_c_…”)_._ _

3. Now modify the program so it tells you how many lines have been entered, and then prints out only lines 2, 3, and 4.

4. Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, therefore:

Calories from fat = fat grams * 9

The percentage of calories from fat can be calculated as follows:

Calories from fat / total calories

If the calories from fat are less than 30 percent of the total calories of the food, it should also display a message indicating the food is low in fat.

Note: The number of calories from fat cannot be greater than the total number of calories in the food item. If the program determines that the number of calories from fat is greater than the number of calories in the food item, it should display an error message indicating the input is invalid.