Q. Fill In the missing lines of code in the following code. The code reads in a limit amount a prices and prints the largest price that is less than the limit. You can assume that all prices and the limit are positive numbers. When a price 0 is entered the program terminates and prints the largest price that is less than the limit.


# Read the limit.
limit = float(input ('enter the limit'))
max_price = 0
#Read the next price
next_price = float(input ("Enter a price or to stop:"))
while next_price > 0 :
    <write your code here>
    # Read the next price
    <Write your code here>
if max_price > 0 :
    <Write your code here>
else :
    <Write your code here>


Answer =

 

# Read the limit.
limit = float(input ('enter the limit'))
max_price = 0
#Read the next price
next_price = float(input ("Enter a price or to stop:"))
while next_price > 0 :
    if next_price > max_price and next_price < limit :
        max_price = next_price
    # Read the next price
    next_price = float(input ("Enter a price or to stop:"))
if max_price > 0 :
    print("Largest number :-",max_price)
else :
    print("Invalid")

8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post