0% found this document useful (0 votes)
41 views

Python Program New Assignement

The document contains 5 questions related to writing Python programs. Question 1 asks to write a program that calculates body mass index (BMI) based on a user's weight and height. Question 2 asks to write a program that converts seconds entered by the user to minutes, hours, days format depending on the number of seconds. Question 3 asks to write a program that calculates discount and total cost for software packages purchased based on quantity. Question 4 asks to write a program that calculates shipping charges based on the weight of a package. Question 5 asks to write a program that calculates reward points earned based on number of books purchased.

Uploaded by

Waseem Hassan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Python Program New Assignement

The document contains 5 questions related to writing Python programs. Question 1 asks to write a program that calculates body mass index (BMI) based on a user's weight and height. Question 2 asks to write a program that converts seconds entered by the user to minutes, hours, days format depending on the number of seconds. Question 3 asks to write a program that calculates discount and total cost for software packages purchased based on quantity. Question 4 asks to write a program that calculates shipping charges based on the weight of a package. Question 5 asks to write a program that calculates reward points earned based on number of books purchased.

Uploaded by

Waseem Hassan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Programes

Q NO : 01
Body Mass Index Write a program that calculates and displays a
person’s body mass index (BMI). The BMI is often used to determine
whether a person is overweight or underweight for his or her height. A person’s
BMI is calculated with the following

formula: BMI 5 weight 3 703/height2

where weight is measured in pounds and height is measured in inches. The program should
ask the user to enter his or her weight and height, then
display the user’s BMI. The pro- gram should also display a message
indicating whether the person has optimal weight, is underweight, or is overweight. A
person’s weight is considered to be optimal if his or her BMI is between 18.5
and 25. If the BMI is less than 18.5, the person is
considered to be underweight. If the BMI value is greater
than 25, the person is considered to be overweight.

Input
# 14. Body Mass Index

# Write a program that calculates and displays a person’s

# body mass index (BMI). The BMI is often used to determine

# whether a person is overweight or underweight for his or

# her height. A person’s BMI is calculated with the following

# formula:

# BMI = weight * 703 / height^2

# where weight is measured in pounds and height is measured


# in inches. The program should ask the user to enter his

# or her weight and height, then display the user’s BMI.

# The program should also display a message indicating

# whether the person has optimal weight, is underweight, or

# is overweight. A person’s weight is considered to be optimal

# if his or her BMI is between 18.5 and 25. If the BMI is less

# than 18.5, the person is considered to be underweight. If the

# BMI value is greater than 25, the person is considered to

# be overweight.

weight = float(input("Enter weight (in pounds): "))

height = float(input("Enter height (in inches): "))

message = "Your weight is considered "

BMI = (weight * (703 / (height**2)))

if BMI >= 18.5 and BMI <= 25:

message += "optimal weight"

elif BMI < 18.5:

message += "underweight"

elif BMI > 25:

message += "overweight"

message += " @ BMI = " + format(BMI, ',.2f')

print(‘message4’)
output

Q NO :02
Write a program that asks the user to enter a number of seconds and works as follows: •
There are 60 seconds in a minute. If the number of
seconds entered by the user is greater than or equal to 60,
the program should convert the number of seconds to minutes and seconds. • There are 3,600
seconds in an hour. If the number of seconds entered by the user is greater than or equal to
3,600, the program should convert the number of seconds to hours, minutes, and seconds. •
There are 86,400 seconds in a day. If the number of seconds entered by the user is
greater than or equal to 86,400, the program should convert the number of seconds to days,
hours, minutes, and seconds.

Input
# Write a program that asks the user to enter a number of

# seconds and works as follows:

# • There are 60 seconds in a minute. If the number of

# seconds entered by the user is greater than or equal to

# 60, the program should convert the number of seconds to

# minutes and seconds.


# • There are 3,600 seconds in an hour. If the number of

# seconds entered by the user is greater than or equal to 3,600,

# the program should convert the number of seconds to hours,

# minutes, and seconds.

# • There are 86,400 seconds in a day. If the number of

# seconds entered by the user is greater than or equal to

# 86,400, the program should convert the number of seconds to

# days, hours, minutes, and seconds.

number_of_seconds = int(input("Enter number of seconds: "))

message = ""

if number_of_seconds < 0:

message = "Enter a number above 0.\n" + \

"Rerun program and try again."

else:

if number_of_seconds >= 0 and number_of_seconds < 60:

seconds = format(number_of_seconds % 60)

message = "Seconds = " + seconds

elif number_of_seconds >= 60 and number_of_seconds < 3600:

minutes = format(number_of_seconds // 60)

seconds = format(number_of_seconds % 60)

message = "Minutes = " + minutes + \

" Seconds = " + seconds

elif number_of_seconds >= 3600 and number_of_seconds < 86400:

hours = format(number_of_seconds // 3600)

minutes = format((number_of_seconds % 3600) // 60)


seconds = format((number_of_seconds % 3600) % 60)

message = "Hours = " + hours + " " + \

"Minutes = " + minutes + " " + \

"Seconds = " + seconds + " "

elif number_of_seconds >= 86400:

days = format(number_of_seconds // 86400)

hours = format((number_of_seconds % 86400) // 3600)

minutes = format(((number_of_seconds % 86400) % 3600) // 60)

seconds = format(((number_of_seconds % 86400) % 3600) % 60)

message = "Days = " + days + " " + \

"Hours = " + hours + " " + \

"Minutes = " + minutes + " " + \

"Seconds = " + seconds + " "

print(message)

Output

Q NO :03
A software company sells a package that retails for $99. Quantity discounts are given
according to the following table:
Quantity Discount

10–19 10%

20–49 20%

50–99 30%

100 or more 40%

Write a program that asks the user to enter the number of packages purchased. The pro- gram
should then display the amount of the discount (if any) and the total amount of the purchase
after the discount.

Input
4040# 12. Software Sales

# A software company sells a package that retails for $99.

# Quantity discounts are given according to the following

# table:

# Quantity Discount

# 10–19 10%

# 20–49 20%

# 50–99 30%

# 100 or more 40%

# Write a program that asks the user to enter the number of

# packages purchased. The program should then display the

# amount of the discount (if any) and the total amount of

# the purchase after the discount.

PRICE_PER_PACKAGE = 99.00
number_of_packages = float(input('\nEnter # of packages purchased: '))

display_message = ""

if number_of_packages < 0:

display_message = "Error. # of packages must be greater than 0.\nRe-run program and try
again."

else:

discount_percentage = 0

if number_of_packages < 10:

discount_percentage = 0

elif number_of_packages >= 10 and number_of_packages <= 19:

discount_percentage = .10 # 10%

elif number_of_packages >= 20 and number_of_packages <= 49:

discount_percentage = .20 # 20%

elif number_of_packages >= 50 and number_of_packages <= 99:

discount_percentage = .30

elif number_of_packages >= 100:

discount_percentage = .40 # 40%

package_total = number_of_packages * PRICE_PER_PACKAGE

discount_amount = (package_total) * discount_percentage

grand_total = package_total - discount_amount

display_message = "Package total = $" + format(package_total, ',.2f') + \

"\nDiscount Percentage = " + format(discount_percentage, '.0%') + \


"\nDiscount amount = $" + format(discount_amount, ',.2f') + \

"\nGrand total = $" + format(grand_total, ',.2f')

print("\n" + display_message + "\n")

Output

Q NO : 04
The Fast Freight Shipping Company charges the following rates:

Weight of Package Rate per Pound

2 pounds or less $1.50

Over 2 pounds but not more than 6 pounds $3.00

Over 6 pounds but not more than 10 pounds $4.00

Over 10 pounds $4.75

Write a program that asks the user to enter the weight of a package then displays the ship-
ping charges.
Input
weight_of_package = float(input("Enter weight of package: "))

shipping_charges = 0.0

message = "Shipping charges = "

if weight_of_package <= 2:

shipping_charges = weight_of_package * 1.50

elif weight_of_package > 2 and weight_of_package <= 6:

shipping_charges = weight_of_package * 3.00

elif weight_of_package > 6 and weight_of_package <= 10:

shipping_charges = weight_of_package * 4.00

elif weight_of_package > 10:

shipping_charges = weight_of_package * 4.75

message += "$" + format(shipping_charges, ',.2f')

print(message)

Output
Q NO : 05
Serendipity Booksellers has a book club that awards points to its customers based on the
number of books purchased each month. The points are awarded as follows:

• If a customer purchases 0 books, he or she earns 0


points.

• If a customer purchases 2 books, he or she earns 5 points.

• If a customer purchases 4 books, he or she earns 15 points.

• If a customer purchases 6 books, he or she earns 30 points.

• If a customer purchases 8 or more books, he or she earns 60 points.

Write a program that asks the user to enter the number of books that he or she has pur-
chased this month, then displays the number of points awarded.

Input
number_of_books = int(input("Enter the number of books: "))

message = ""
if number_of_books < 0:

message = "Error. Enter a positive number. \n" + \

"Re-run program and try again."

else:

message = "You are awared "

if number_of_books >= 0 and number_of_books <= 1:

message += "0 "

elif number_of_books >= 2 and number_of_books <= 3:

message += "5 "

elif number_of_books >= 4 and number_of_books <= 5:

message += "15 "

elif number_of_books >= 6 and number_of_books <= 7:

message += "30 "

elif number_of_books >= 8:

message += "60 "

message += "points."

print(message)

Output

You might also like