Question

In: Computer Science

implement the following logic in Python, use appropriate data types. Data types are represented as either...

implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string.

string name

string address

num item

num quantity

num price

num SIZE = 6

num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688

num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00

num sub

string foundIt = “N”

string MSG_YES = “Item available”

string MSG_NO = “Item not found”

get name, address, item, quantity

sub = 0

while sub <= SIZE

if item == VALID_ITEM [sub] then

foundIt = “Y”

price = VALID_ITEM_PRICE [sub]

endif

sub = sub + 1

endwhile

if foundIt == “Y” then

print MSG_YES

print quantity, “ at “ , price, “ each”

print “Total “, quantity * price

else

print MSG_NO

endif

IN PYTHON

Solutions

Expert Solution

#declare valid item list
VALID_ITEM = [106,108,307,405,457,688]

#declare price for item
VALID_ITEM_PRICE = [0.59,0.99,4.50,15.99,17.50,39.00]

#inititalize sub to 0
sub = 0

#inititalize size to 6
SIZE = 6
foundit = 'N'

#takes name from user and store it in name variable
name = input("Enter name: ")

#takes address from user and store it in address variable
address = input("Enter address: ")

#takes item from user and store it in item variable
item = input("Enter item: ")

#takes quantity from user and store it in quantity variable
quantity = input("Enter quantity: ")

#checks if entered item is found in valid item list
#if found then change the value of foundit to Y 
# and store the price value for that item in price variable
while (sub < SIZE):
    if(int(item) ==  VALID_ITEM[sub]):
        foundit = 'Y'
        price = VALID_ITEM_PRICE[sub]
    sub = sub+1

#if foundit is Y then Item is availabe
#prints quantity and price for that Item and total price     
if(foundit == 'Y'):
    print("Item available")
    print(quantity ," at ", price, " each ")
    print("Total: ", int(quantity) *float(price))

#if foundit is N then item not found in VALID_ITEM list
#prints item not found
else:
    print("Item not found")


OUTPUT:


Related Solutions

Write if logic in Python that checks if a variable named number is either greater than,...
Write if logic in Python that checks if a variable named number is either greater than, less than , or equal to 10 and prints out the number with the appropriate message, for example, if number is 6 you would output: number,"less than 10" or 6 less than 10
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1....
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1. Accept a message as keyboard input to your program. 2. Accept a secret key for the sender/recipient as keyboard input to your program. 3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR,...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding)
Implement the following logic function as embedded logic inside a positive TSPC register. F= ab +...
Implement the following logic function as embedded logic inside a positive TSPC register. F= ab + bcd + ad
Cryptography - please use Python to complete the following task. You don't have to implement AES...
Cryptography - please use Python to complete the following task. You don't have to implement AES just import the necessary libraries. Can you fix my code? Thanks! Read in a 128 bit key from the user (16 characters). If the user enters a key of any other size it's fine to terminate the program with an error. Read in a string of arbitary length from the user. (ie, the string could be 1 character, or 50,000, or anywhere in between)....
you can use either vim or nano as text editor Implement the following code in ARM...
you can use either vim or nano as text editor Implement the following code in ARM on Raspberry Pi, compile and run. g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note: answer should be calculated not hardcoded
1. What are the main data types in Python? Which data types are sequences? 2. What...
1. What are the main data types in Python? Which data types are sequences? 2. What are some general guidelines for naming a ‘variable’ in Python? Give at least three examples of variable names that follow these guidelines 3. Provide an example of the Python syntax to create a variable to hold the age of a building (for example,40 years old). a. Provide the Python syntax to test whether the variable created above is more than 35, and print the...
For the following statistical procedures please describe 1) the types of data appropriate for the response...
For the following statistical procedures please describe 1) the types of data appropriate for the response and explanatory variables (ie- continuous vs categorical), 2) the number of groups and levels for each, 3) Null and Alternate Hypotheses, 4) Assumptions and primary diagnostics. a. One Sample T Test b. Chi Square Test c. One way ANOVA d. Simple Linear Regression
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT