Question

Please answer this using def (functions) in python 3 with a single print statement under #main....

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.

Homework Answers

Answer #1

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

.

Know the answer?
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
Similar Questions
In Python def main(): c = 10 print("Welcome to Roderick's Chikkin and Gravy") e = False...
In Python def main(): c = 10 print("Welcome to Roderick's Chikkin and Gravy") e = False while not e: x = input("Would you like some chikkin?") if x == "Y" or x == "y": c = f(c) else: e = True if c == 0: e = True print("I hope you enjoyed your chikkin!") def f(c): if c > 0: print("Got you some chikkin! Enjoy") return c-1 else: print("No chikkin left. Sorry") return 0 main() For practice with lists, create...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION"...
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...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression Evaluator as described in section 7-3b of the book. The program should ask the user for a string that contains a Postfix Expression. It should then use the string's split function to create a list with each token in the expression stored as items in the list. Now, using either the stack classes from 7.2 or using the simulated stack functionality available in a...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if input from user is empty -> get an error string variable if input is not empty -> use preg_match() to match the pattern $pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/"; -> if it's a matched, get a success string variable */           } ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link...
One way to represent a very large integer (one that won't fit into a variable of...
One way to represent a very large integer (one that won't fit into a variable of type short, int, or even long) is to use an array. The array is of type int, so each element in the array can hold an integer -- we will store just one digit of our number per array element. So if a user entered 2375, it might be stored as -------------------------- | 2 | 3 | 7 | 5 | ... | --------------------------...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Consider insertsort. Suppose that the input array A has 1% probability to be monotonically decreasing. Show...
    asked 4 minutes ago
  • Your company is thinking of introducing a Bring Your Own Device (BYOD) policy. You have been...
    asked 11 minutes ago
  • Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
    asked 13 minutes ago
  • Suppose the number of cars in a household has a binomial distribution with parameters n =...
    asked 16 minutes ago
  • HR needs some information on the new interns put into a database. Given an id, email,...
    asked 37 minutes ago
  • Problem solving strategies Questions years = input("Enter a number of years and I'll tell you how...
    asked 41 minutes ago
  • Calculate ?Hrxn for the following reaction: CH4(g)+4Cl2(g)?CCl4(g)+4HCl(g) Use the following reactions and given ?H?s. C(s)+2H2(g)?CH4(g)?H=?74.6kJC(s)+2Cl2(g)?CCl4(g)?H=?95.7kJH2(g)+Cl2(g)?2HCl(g)?H=?184.6kJ Express...
    asked 48 minutes ago
  • ASCII (American Standard Code for Information Interchange) has an encoding for every character of the alphabet,...
    asked 1 hour ago
  • Is home confinement with electronic monitoring a deterrent? Are there negatives to being confined to one’s...
    asked 1 hour ago
  • Social hostility can have severe lasting effects of interperpersonal relationship during our adolescence years, which if...
    asked 1 hour ago
  • - A series RLC circuit has R=15 ?, L=1.5 H, and C=15 ?F. (a) For what...
    asked 1 hour ago
  • TV Circuit has 30 large-screen televisions in a warehouse in Erie and 60 large-screen televisions in...
    asked 1 hour ago