NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION"
PROGRAM 3_1:-
Write a program that determines the cost of online order of T-shirts. T-shirts are priced at $12.99 each, but discounts are applied for quantities as follows:
- 12 or more shirts earn a 30% discount and free shipping
- 6-11 shirts earn a 20% discount
- and 3-5 shirts earn a 10% discount
- 1 or 2 shirts, no discounts
Prompt the user to enter the quantity desired and then calculate the cost of the order, including shipping if applicable. Ignore tax. Shipping costs are $8.99. The charges should be displayed in currency format with the $ sign right up against the first digit.
PROGRAM 3_2:-
Write a program named program33.py that prompts the user to enter an odd number between 30 and 80 and then responds to user input. Code the program to respond to all four possible responses as shown in the sample outputs below.
Sample Outputs (3)
Enter an odd number between 30 and 80 89
That was odd but out of required range
===========================================
Enter an odd number between 30 and 80 50
That was in range but it was even, not odd
===========================================
Enter an odd number between 30 and 80 100
That input was out of range and not odd
Please help me with this python question?
============================================
Enter an odd number between 30 and 80 57
Good input
Program 3_1 -
Here is the code, with comments for clear understanding (round has been used while printing so that the answer is printed up to two decimal places)
price = 12.99 # declare the price variable
shipping = 8.99 # declare the shipping variable
n = int(input("Enter quantity of T-Shirts: ")) # ask the quantity
from user
total_cost = n*12.99 # calculate total cost by multiplying quantity
by price
if n>=12: # if number of t-shirts are more than 12
total_cost = total_cost - 0.3*total_cost # calculate the discounted
price
# no shipping charges here
elif n>=6 and n<=11: # if number of t-shirts are in a range
of 6-11
total_cost = total_cost - total_cost*0.2 # calculate the discounted
price
total_cost = total_cost + 8.99 # add the shipping charges
elif n>=3 and n<=5: # if number of t-shirts are in a range of
3-5
total_cost = total_cost - total_cost*0.1 # calculate the discounted
price
total_cost = total_cost + 8.99 # add the shipping charges
elif n==1 or n==2: # if number of t-shirts is 1 or 2
# no discount in this case
total_cost = total_cost + 8.99 # add the shipping charges
print("Total cost is: $",round(total_cost,2))
Code Screenshot -
Output Screenshot -
Program 3_2 -
Here is the code, with comments for clear understanding -
# % sign is used to check the remainder of a number which can
tell if a
# number is even or odd. For example, 6 is an even number and 6%2
gives us
# remainder when 6 is divided by 2 that is 0. Let us take 9, 9%2
gives us
# remainder when 9 is divided by 2 that is 1. So we can say that if
n%2
# is 1,then n is odd, otherwise it is even
n = int(input("Enter an odd number between 30 and 80 ")) # ask for the input
if n<30 or n>80: # if n is less than 30 or more than
80
if n%2 == 0: # and also if n is even
print("That input was out of range and not odd") # print the
result
else: # if n is less than 30 or more than 80 and n is odd
print("That was odd but out of required range") # print the
result
elif n>30 and n<80: # if n is more than 30 and less than
80
if n%2==0: # and also if n is even
print("That was in range but it was even, not odd") # print the
result
else: # if n is more than 30 and less than 80 and also n is
odd
print("Good input") # print the result
Code Screenshot -
Output Screenshot -
PLEASE REFER TO THE CODE SCREENSHOT FOR PROPER INDENTATION.
ALL THE BEST !!
Get Answers For Free
Most questions answered within 1 hours.