SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:9 | ISBN:978013274719 | Edition: 6

Question

(Financial: compare costs) Suppose you shop for rice and find it in two differentsized packages. You would like to write a program to compare the costs of the packages. The program prompts the user to enter the weight and price of each package and then displays the one with the better price. Here is a sample run:

Enter weight and price for package 1: 50, 24.59
Enter weight and price for package 2:25, 11.99
Package 1 has the better price.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

SOURCE CODE:

# Enter weight and price for package1
print("Enter weight and price for package1 : ")
a=eval(input())
b=eval(input())
# Enter weight and price for package2
print("Enter weight and price for package2 : ")
c=eval(input())
d=eval(input())
# Checking for better price
if b > d:
    print("Package 1 has the better price")
else:
    print("Package 2 has the better price")

OUTPUT:

 Enter weight and price for package1 :
 20
 50
 Enter weight and price for package2 :
 30
 60
 Package 2 has the better price
 
 

 

0 0

Discussions

Post the discussion to improve the above solution.