##### Question

In: Computer Science

# Please solve the following using if statements in python 3. User specifies the number of books...

Please solve the following using if statements in python 3.

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 upto 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.

## Solutions

##### Expert Solution

Code and output Code for copying

n=int(input("Enter 1 for online 0 for offline: "))
m=int(input("Enter number of books purchased: "))

if n==1:
if m<=10:
j=(m*15)
j+=(m*25)/100

print("the total cost is {} dollars".format(j))
if m>10:
j=(m*15)
r=m-10
j+=(r*5)
j+=(10*25)/100
print("the total cost is {} dollars".format(j))
if n==0:
j=m*15
j=j+(j*(0.08))
print("the total cost is {} dollars".format(j))

Code snippet

n=int(input("Enter 1 for online 0 for offline: "))
m=int(input("Enter number of books purchased: "))

if n==1:
if m<=10:
j=(m*15)
j+=(m*25)/100

print("the total cost is {} dollars".format(j))
if m>10:
j=(m*15)
r=m-10
j+=(r*5)
j+=(10*25)/100
print("the total cost is {} dollars".format(j))
if n==0:
j=m*15
j=j+(j*(0.08))
print("the total cost is {} dollars".format(j))



Using function-

Code and output Code for copying

def fun(n,m):
if n==1:
if m<=10:
j=(m*15)
j+=(m*25)/100

if m>10:
j=(m*15)
r=m-10
j+=(r*5)
j+=(10*25)/100

if n==0:
j=m*15
j=j+(j*(0.08))
return "the total cost is {} dollars".format(j)

n=int(input("Enter 1 for online 0 for offline: "))
m=int(input("Enter number of books purchased: "))
print(fun(n,m))

Code snippet

def fun(n,m):
if n==1:
if m<=10:
j=(m*15)
j+=(m*25)/100

if m>10:
j=(m*15)
r=m-10
j+=(r*5)
j+=(10*25)/100

if n==0:
j=m*15
j=j+(j*(0.08))
return "the total cost is {} dollars".format(j)

n=int(input("Enter 1 for online 0 for offline: "))
m=int(input("Enter number of books purchased: "))
print(fun(n,m))

## Related Solutions

##### Can you please solve these questions/ statements using python? I started with "importing" the file. I...
Can you please solve these questions/ statements using python? I started with "importing" the file. I only need question one to be answered not two-four. Can use whatever data frame of choice, I just need a sample code for each line. Thank you #1. #Fit a linear regression model on data: USA_housing.csv to predict the Price of the house. import pandas as pd housing_df = pd.read_csv("USA_Housing.csv") #Income: Avg. area income #Age: Avg age of the houses #Bedrooms: Avg No of...
##### Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to...
Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to see if the value is a number between 1 and 10 #if number is too high or too low, tell user, if they guessed it break out of loop Display "Welcome to my Guess the number program!" random mynumber count=1 while True try Display "Guess a number between 1 and 10"   Get guess while guess<1 or guess>10 Display "Guess a number between 1 and...
##### Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
##### ​​​​​​​ASAP PLEASE Write a python code that prompts a user to input a 10-digit phone number....
​​​​​​​ASAP PLEASE Write a python code that prompts a user to input a 10-digit phone number. The output of your code is the phone number’s  area code, prefix and line number separated with a space on a single line e.g INPUT 2022745512 OUTPUT 202 274 5512 write a code that will prompt a user to input 5 integers and output its largest value. PYTHON e.g INPUT 2 4 6 1 3 OUTPUT Largest value is: 6
##### USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to...
USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negative number or zero you should re-prompt them. Next, determine if the given number is a prime number. A prime number is a number that has no positive divisors other than 1 and itself. For example, 5 is prime because the only numbers that evenly divide into 5 are...
##### In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
##### In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
##### in PYTHON Determine whether a number provided by the user is perfect or not. write a...
in PYTHON Determine whether a number provided by the user is perfect or not. write a program that: 1. Ask the user for a positive integer 2. Compute the list of integer divisors of the given number 3. Check whether the given number is perfect 4. Communicate the result to the user (something like ‘Your number…. Is a perfect number’ or ‘Your number ….. is not a perfect number’. 5. In any case, communicate to the user the list of...
##### use python to solve Write a function called word_chain that repeatedly asks the user for a...
use python to solve Write a function called word_chain that repeatedly asks the user for a word until either (1) the user has entered ten words, or (2) the user types nothing and presses enter. Each time the user enters an actual word, your program should print all the words entered so far, in one long chain. For example, if the user just typed "orange", and the user has already entered "apple" and "banana", your program should print "applebananaorange" before...
##### using python: Given an arbitrary whole number, please write an if statement to output if it...
using python: Given an arbitrary whole number, please write an if statement to output if it is an even number or an odd number