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...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
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...
Please write a java program (using dialog box statements for user input) that has the following...
Please write a java program (using dialog box statements for user input) that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled,...
Python! Create a program that does the following: Reads a number from the user. Calls a...
Python! Create a program that does the following: Reads a number from the user. Calls a function that finds all the divisors of that number. Calls another function to see if the number 7 is a divisor of the original number. Keeps reading input from the user and calling the function above until the user enters the letter ‘q’. Create 2 functions findDivisors() and lucky7(). Use docstrings to explain what each function does. Use the help() function to output the...
​​​​​​​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
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...
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...
Please solve the following equation by using the frobenius method. xy′′ − (3 + x)y ′...
Please solve the following equation by using the frobenius method. xy′′ − (3 + x)y ′ + 2y = 0 My apologies, the original image did not upload properly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT