Question

For this lab, modify the python code below so it will continuously be asking user for...

For this lab, modify the python code below so it will continuously be asking user for inputs to calculate the interest earned until the user enters number 0 (zero) in principle. Once the user enters any number less or equal to 0 in principle, the program will end.

here is my code:

# Programming Exercise 3-14

# Local variables
p = 0.0
r = 0.0
n = 0.0
t = 0.0

loop = True


while loop:
p = float(input('\nEnter the starting principal, 0 to quit: '))
  
if p > 0:

r = float(input('Enter the annual rate: '))

total = p * (1 + float(r / 100) / n) ** (n * t)
interest = total - p
  
print('At the end of years you will have $ with interest earned', format(t, total, interest))
else:
loop = False
print ('Program exiting ...')

im not sure what is wrong in my code... please help asap

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: here is the answer for your question :

PYTHON CODE:

while True:

p = float(input('Enter the starting principal, 0 to quit: '))# input principal amount

if p > 0:

t=float(input('Enter the time duration:'))# input time from user

n=12

r = float(input('Enter the annual rate: '))# input rate

total = p * (1 + float(r / (100 * n))) ** (n * t)# calculate the toatl aount

interest = total - p# calculating the interest# interest earned

print('At the end of {} years you will have ${:.2f} as interest earned'.format( t,interest))

else:

print ('Enter principal > 0 ..Program exiting ...')

break # break is used to break the loop when condition is not meet

SNIPPET:

main.py E saved while True: p = float(input(Enter the starting principal, o to quit: ))# input principal amount BEOOWN if p

OUTPUT:

Enter the starting principal, o to quit: 2000 Enter the time duration: 10 Enter the annual rate: 5 At the end of 10.0 years y

I hope this would help you out,If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
For this lab, modify the python code below so it will continuously be asking user for...
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 PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • [Using Python] I need my code given below to loop the user input, so that you...

    [Using Python] I need my code given below to loop the user input, so that you are asked to input without it stopping after 4 inputs. Code: #A program that converts a hexadecimal number to its decimal value #Define function for hexadecimal to decimal def hexToDec(hexi): result = 0 #For loop to test input for correct values for char in hexi: if 'A' <= char <= 'F' or 'a' <= char <= 'f': if 'a' <= char <= 'f': result...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

  • solve using the code provided Write a program that will continuously read words from the user,...

    solve using the code provided Write a program that will continuously read words from the user, word by word till the user enter "quit”, the program should print each word in reverse order. Sample Session: (User input in Red color) Enter a word: hello olleh Enter a word: Ahmad damhA Enter a word: quit Good Bye 9 dinclude <iostream> 10 dinclude <cstring> 11 using namespace std; 12 13 int main() { 14 15 char word(100); 16 cin>>word; 17 while (strcmp(word,...

  • Python code

    Write a Python program that takes the value of n from the user and calculates the value of S using the following equation:S = 1! - 2! + 3! - 4! + 5! - 6! + ……..  n!Here, the value of n should be a positive (n>0) integer. If the user gives a negative input or zero, then print “Invalid Input!”. Also, print the sentence “End of program.” in the last line no matter what the input is.---------------------------------------------------------------------Sample Input 1:4Sample Output 1:Value of...

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • ANS (2) 0R hat output is produced by the following code if user enters these values...

    ANS (2) 0R hat output is produced by the following code if user enters these values for a question asked by the progran .User entered 3 Enter a positive integer value! (enter -1 to end) :3 Enter a positive integer value! (enter -1 to end) five Enter a positive integer value! (enter -1 to end) :7 Enter a positive integer value! (enter -1 to end) :-1 User entered five -User entered 7 ...User entered -1 import java.util.Scanner: class Verify input...

  • Create a program in Python that will allow the user to enter a temperature in Fahrenheit...

    Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...

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