Please answer this using def (functions) in python 3 with a single print statement under #main.
Is this possible to do in one print as output?
User specifies the number of books ordered, and if the order is online, or not. You can collect the second input by asking the user to enter 1 for online, and 0 for offline. You can assume that the user will enter 1 or 0 as directed.
Unit price for a book is 15$.
Online orders get shipping cost added: per book 25 cents up to 10 books, after that, flat rate of 5$.
Offline orders get taxed, at 8%.
(that is: no ship cost for offline orders, no tax for online orders)
App displays: Order price, inclusive of shipping/tax
Hints:
1. The input 1 or 0 typed by user will come in as ‘1’ or ‘0’, strings.
2. In Python, the 1 is equivalent to true, and 0 is equivalent to false. So if you have a variable holding the 1/0 value for online/ offline, you can use that variable as if it were a boolean variable. Note you can do this problem equally well without using this hint.
Code
def book():
n=int(input()) #ninput numver of books
m=int(input()) # input order type
p=n*15
if m: # if online order
if n>10: #more than 10 books flat ptice
p= p+ 5
else:
p= p+ (n*0.25) #less than 10 books 25 cents per book
else: #if offline order
t = (p*(8)/100) #8% tax
p = p+t
print(p,end='') #print the result
print ('$')
if __name__ == "__main__":
book() #call the function
Terminal Work
.
Get Answers For Free
Most questions answered within 1 hours.