Question

Write a Python program stored in a file q3.py that asks for the prices of items...

Write a Python program stored in a file q3.py that asks for
the prices of items and your money amount as input, and prints the options of items
along with cost as output.

Enter list of prices : 7 3 9 12 26 17 8 9
Enter dollar amount : 16

You have total 8 options
Option 1: You can buy item 1 and item 2 with $10 .0.
Option 2: You can buy item 1 and item 3 with $16 .0.
Option 3: You can buy item 1 and item 7 with $15 .0.
Option 4: You can buy item 1 and item 8 with $16 .0.
Option 5: You can buy item 2 and item 3 with $12 .0.
Option 6: You can buy item 2 and item 4 with $15 .0.
Option 7: You can buy item 2 and item 7 with $11 .0.
Option 8: You can buy item 2 and item 8 with $12 .0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
price_list = list(map(float, input('Enter list of prices : ').split()))
amount = float(input('Enter dollar amount : '))
option = 1

print()
print('You have total', len(price_list), 'options')

for i in range(len(price_list)):
  for j in range(i+1, len(price_list)):

    # checking if the price for two items is less or equal to amount
    if float(price_list[i]) + float(price_list[j]) <= amount:

      # displaying the result
      print('Option {}: You can buy item {} and item {} with ${}'.format(option, i+1, j+1, float(price_list[i]) + float(price_list[j])))
      option += 1

For help comment.

Thank You

Add a comment
Know the answer?
Add Answer to:
Write a Python program stored in a file q3.py that asks for the prices of items...
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 stored in a file q2.py that asks for a starting number and...

    Write a Python program stored in a file q2.py that asks for a starting number and an ending number, and then prints all the Fibonacci numbers between them (and including the starting and ending numbers, if they are also Fibonacci numbers). Each Fibonacci number, must be separated by a space. Example: Enter starting number : 5 Enter ending number : 500 10 Fibonacci numbers between 5 and 500 are : 5 8 13 21 34 55 89 144 233 377

  • CODING IN PYTHON: Assume a customer is at a store purchasing exactly 4 items. The cashier...

    CODING IN PYTHON: Assume a customer is at a store purchasing exactly 4 items. The cashier inputs the items and their prices into the computer. Someone has provided the cashier a Python program that does the following: 1. Asks cashier for name of each item (use short names like nails, paint, etc.) 2. Asks cashier for price of each item A) Assume items are between $5 & $20. Have 1 item that is less than $10 3. Prints receipt header...

  • Using python Problem 6 (10 points). Write a program which asks the user to enter a...

    Using python Problem 6 (10 points). Write a program which asks the user to enter a number and prints its multiplication table upto 10. Sample program output: Please enter a number: 9 9 X 1 = 9 9 X 2 = 18 9 X 3 = 27 9 X 4 = 36 9 X 5 = 45 9 X 6 = 54 9 X 7 = 63 9 X 8 = 72 9 X 9 = 81 9 X 10...

  • In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • I need this python program to access an excel file, books inventory file. The file called...

    I need this python program to access an excel file, books inventory file. The file called (bkstr_inv.xlsx), and I need to add another option [search books], option to allow a customer to search the books inventory, please. CODE ''' Shows the menu with options and gets the user selection. ''' def GetOptionFromUser(): print("******************BookStore**************************") print("1. Add Books") print("2. View Books") print("3. Add To Cart") print("4. View Receipt") print("5. Buy Books") print("6. Clear Cart") print("7. Exit") print("*****************************************************") option = int(input("Select your option:...

  • write this python program 4. Pascal Triangle. Write a program pascal.py that builds and prints a...

    write this python program 4. Pascal Triangle. Write a program pascal.py that builds and prints a two-dimensional list (a list of lists) a such that a[n][k contains the coefficient of the k-th term in the binomial expansion of (ty) These coefficients can be organized in a triangle, famously known as Pascals triangle. Every row in the triangle may be computed from the previous row by adding adjacent pairs of values together. Below is a sample invocation of the program s...

  • please write in python Write a program that asks for beginning and ending number. The program...

    please write in python Write a program that asks for beginning and ending number. The program generates a set of 20 random numbers between the numbers and displays a count of each number generated. Sample output Enter starting and ending number separated by comma: 5, 25 5 occurs 2 times 7 occurs 1 time 8 occurs 1 time 10 occurs 2 times 12 occurs 1 time 13 occurs 2 time 15 occurs 5 times 16 occurs 1 time 20 occurs...

  • implement function 2 in python. name the source file as h1.py. A test file h1_test.py is...

    implement function 2 in python. name the source file as h1.py. A test file h1_test.py is provided below! h1_test.py import re import math import pytest from h1 import (change, strip_quotes, scramble, say, triples, powers) def test_change(): assert change(0) == (0, 0, 0, 0) assert change(97) == (3, 2, 0, 2) assert change(8) == (0, 0, 1, 3) assert change(250) == (10, 0, 0, 0) assert change(144) == (5, 1, 1, 4) assert change(97) == (3, 2, 0, 2) assert change(100000000000)...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

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