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

Please solve everything using Python 3 1. What does list contain after the following code is...
Please solve everything using Python 3 1. What does list contain after the following code is executed? list = [82, 27, 66, 18, 40, 93, 85, 29] list.append(50) list.insert(3, 99) list.pop() a. [82, 27, 66, 99, 18, 40, 93, 85, 29] b. [50, 82, 27, 99, 66, 18, 40, 93, 85] c. [27, 66, 99, 18, 40, 93, 85, 29, 50] d. [82, 27, 99, 66, 18, 40, 93, 85, 29] 2. What does list contain after the following code...
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...
Solve following tasks using MIPS Task Write a program that gets a number from user and...
Solve following tasks using MIPS Task Write a program that gets a number from user and displays “Even”, or “Odd. (If-else) Write a program that input a number from user displays each digit separately. For example if input is 3986, output is  6, 8, 9 ,3. (Loop) Write a program that converts a decimal number to binary. (Loop) Hint for Task 1 and Task 3.     Use, div $tdivident,$tdivider and mfhi $tdestination instructions. For example, Div $t1,$t2 will divide $t1...
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....
User Python to solve; show all code: A user will enter in data for a basketball...
User Python to solve; show all code: A user will enter in data for a basketball team. For each player on the team the user will enter The player’s last name The average number of point the player scored last season The number of games the player is projected to play in this year Write a program that will prompt the user for the player data described above. The user does not know how many players are on the team...
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,...
​​​​​​​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
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT