Project 5 - intro to python
Write a program in python that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, four pennies the third day, and continues to double each day. Output the amount earned each day .. and the total pay at the end.
The Algorithm (Plan) for your program would be:
Ask the user for the number of days to be worked
Verify that the amount entered is positive, and if not, continue to ask the fuser or an amount ..until a valid number is entered
For each day worked
Calculate the pay
Print out the pay
Add the daily pay to the final total
Print out the final total of pennies
Print out the final total in dollars and cents form
SAMPLE OUTPUT would look like:
How many days will you work? -5
Please reenter .. days must be positive -10
Please reenter .. days must be positive 0
Please reenter .. days must be positive 16
Day 1 : 1 pennies
Day 2 : 2 pennies
Day 3 : 4 pennies
Day 4 : 8 pennies
Day 5 : 16 pennies
Day 6 : 32 pennies
Day 7 : 64 pennies
Day 8 : 128 pennies
Day 9 : 256 pennies
Day 10 : 512 pennies
Day 11 : 1024 pennies
Day 12 : 2048 pennies
Day 13 : 4096 pennies
Day 14 : 8192 pennies
Day 15 : 16384 pennies
Day 16 : 32768 pennies
Total amount earned 65535 pennies
or ..655 dollars and 35 cents
please make sure that each control structure is commented to indicate the task it is performing, and any code that is not obvious is briefly commented as well.
thank you
Python 3 code for above problem-
# taking input in "days" variable
days=input("How many days will you work? ");
#checking if "days" is positive and asking for another input
while(days<=0):
days=input("Please reenter .. days must be positive ");
# "total" to calculate the total amount earned.
total=0;
# iterating from 1 to days
for i in range(1,days+1):
# calculating the total amount
total+=pow(2,i-1);
# printing the amount earned each day
print("Day {0} : {1} pennies".format(i,pow(2,i-1)));
# printing the total amount in pennies
print("Total amount earned {0} pennies".format(total));
# printing the total amount in dollars and cents
print("or ..{0} dollars and {1}
cents".format(total/100,total%100));
Code with input and output-
If the answer helped then please upvote.And for any queries,please comment.
Project 5 - intro to python Write a program in python that calculates the amount of...
Week 5 Project Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, four pennies the third day, and continues to double each day. Output the amount earned each day .. and the total pay at the end. The Algorithm (Plan) for your program would be: Ask the user for the number of days to be...
Write a program using Python that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, then show the total pay at the end of the period. The output should be displayed...
Show Me The Money. (15 points) Write a C++ program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on, with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was...
In Java. Use the concept of LOOPS: 2.Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the...
Write a Java program that calculates how much a person would earn after a period of time, according to the following rules: 1. The starting salary for the first day is $1. 2. The salary will double each day. Ask the user to input the number of days worked. The output should display how much the salary was for each day worked, and show the total pay at the end of the work period. Get output similar to the sample...
In Python. Write a program that will calculate the amount of money a person would earn over a period of time if his/her salary is one penny the first day and two pennies for the second day, and continue to double each day. Hints: Declare variables Get the number of days from the user. Show the salary table for each day 4. Use ‘for loop’ to loop through the range of days (1, num_days +1) 5. Display the total pay...
<!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money a person would earn over // a period of years if his or her salary is one penny the first day, two pennies // the second day, and continues to double each day. The program should ask the // user for the number of years and call the function which will return the total // money earned in dollars and cents, not pennies. Assume...
I need to change this python program into one that counts back the LEAST AMOUNT OF COINS. Ex: if i input 44 as my change, how can i make it show 4 dimes and 4 pennies instead of 1 quarter, a dime, and 9 pennies? heres my code so far in PYTHON " cents=int(input("Please enter the change in Cents: ")) Quarter= int(cents/25)#25cents=1 Quarter Dime =int (cents%25/10)# 10 cents=1 Dime cents =(cents%25)%10 print(Quarter,"quarters",Dime,"dimes and",cents,"cents") "
Write a program that calculates the amount a person would earn over a 30-day period of time if his/her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. A sample output might look...
Describe how you would create a Python program that calculates the exact amount of change to give a customer in denominations of quarters, dimes, nickels, and pennies. For example, if the change is 79 cents, how many of each coin would be needed to give change?