Question

In: Computer Science

Write out code for a nested if statement that allows a user to enter in a...

Write out code for a nested if statement that allows a user to enter in a product name, store the product into a variable called product name and checks to see if that product exists in your nested if statement. You must include 5 product names to search for. If it is then assign the price of the item to a variable called amount and then print the product name and the cost of the product to the console. If it does not find any of the items in the nested if statement, then print that item cannot be found. (using Python Only)

Solutions

Expert Solution

SOLUTION:

Dear Student, I am pasting a code of above your query and i am also commenting on the code for your understading. And also attaching the snapshots of program and it's outputs.

PROGRAM:

# take an input of prduct name and store to product_name variable
product_name = input("Enter product name : ")
# first if condition in this, assign 5 diffent products
if ( product_name=="pen" or product_name == "book" or product_name == "box" or product_name == "pencil" or product_name == "eraser"):
# In the second if condition, assign the product cost
if(product_name == "pen"): #this is for pen
amount = 10
print("The product name is ", product_name ,"and it's cost is ", amount , "rupees")
if(product_name == "book"): #this is for book
amount = 100
print("The product name is ", product_name ,"and it's cost is ", amount , "rupees")
if(product_name == "box"): #this is for box
amount = 150
print("The product name is ", product_name ,"and it's cost is ", amount , "rupees")
if(product_name == "pencil"): #this is for pencil
amount = 5
print("The product name is ", product_name ,"and it's cost is ", amount , "rupees")
if(product_name == "eraser"): #this is for eraser
amount = 8
print("The product name is ", product_name ,"and it's cost is ", amount , "rupees")
else: # If item is not found then print the below message
print("That item cannot be found!")

SNAPSHOTS:

OUTPUT 1:

OUTPUT 2:

OUTPUT 3:

OUTPUT 4:


Related Solutions

In Java: Write a nested loop that allows the user to continuously enter phrases and output...
In Java: Write a nested loop that allows the user to continuously enter phrases and output underscores for each character of the phrase. End when the user enters "done" (ignoring case). Once you have this completed, modify your code so that if the character is whitespace, you print a space " " instead of an underscore - Hint: use Character.isWhitespace(YOURCHARHERE) //returns a boolean.
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
q1) using Matlab make a code that allows a user to enter a function like fractional...
q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity
q1) using Matlab make a code that allows a user to enter a function like fractional...
q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT