Question

In: Computer Science

Can I get this logic in Python? plus what software I can use it to run?...

Can I get this logic in Python? plus what software I can use it to run?

thanks and will rate!!!

Search Lab

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

Solutions

Expert Solution

Below is your solution please go through it. For your better understanding I made it using class so that you can understand constructor,setter and getters concepts.I have called class using object please go through it. Moreover you can use PyCharm,Spyder,PyDev,Jupyter IDE to run. If you find difficulty use can use any online Python IDE to get output.

SOLUTION

class Logic: #created logic class for setter getter and constructor
def __init__(self, name,address,item=0,quantity=0,price=0): #initialization of the variables
self._name=name
self._address=address
self._item=item
self._quantity=quantity
self._price=price
def get_name(self):
return self._name
def get_address(self):
return self._address
def get_item(self):
return self._item
def get_quantity(self):
return self._quantity
def get_price(self):
return self._price
def set_price(self, price):
self._price = price
o1= Logic("",""); #passing name and address as null you can pass any parameters and can also pass #other variables like item,quantity and price   
SIZE=6
VALID_ITEM = [106, 108, 307, 405, 457, 688]
VALID_ITEM_PRICE =[0.59, 0.99, 4.50, 15.99, 17.50, 39.00]
sub=0
foundIt ="N"
MSG_YES = "Item available"
MSG_NO = "Item not found"
while(sub<=SIZE-1): #whileloop
if(o1.get_item()== VALID_ITEM [sub]):
foundIt = "Y"
o1.set_price(VALID_ITEM_PRICE [sub])
sub = sub + 1
if (foundIt == "Y"):
print (MSG_YES)
print (o1.get_quantity() ," at ", price," each")
sum=quantity*price
print ("Total",sum)
else:
print (MSG_NO)


Related Solutions

I cannot get this code to run on my python compiler. It gives me an expected...
I cannot get this code to run on my python compiler. It gives me an expected an indent block message. I do not know what is going on. #ask why this is now happenning. (Create employee description) class employee: def__init__(self, name, employee_id, department, title): self.name = name self.employee_id = employee_id self.department = department self.title = title def __str__(self): return '{} , id={}, is in {} and is a {}.'.format(self.name, self.employee_id, self.department, self.title)    def main(): # Create employee list emp1...
what is the solution of this code? Also how would I run it in python to...
what is the solution of this code? Also how would I run it in python to check? q = Queue() q.enqueue(10) q.enqueue(12) q.enqueue(15) for i in range(len(q)): → if len(q) % 2 == 0: → → q.enqueue(q.dequeue()) → else: → → q.dequeue() print(q)
When using scapy in python how can I get the same result as the snippit bellow?...
When using scapy in python how can I get the same result as the snippit bellow? (which in run in terminal) >>> sr(IP(dst="192.168.8.1")/TCP(dport=[21,22,23])) Received 6 packets, got 3 answers, remaining 0 packets (<Results: UDP:0 TCP:3 ICMP:0 Other:0>, <Unanswered: UDP:0 TCP:0 ICMP:0 Other:0>) >>> ans,unans=_ >>> ans.summary() IP / TCP 192.168.8.14:20 > 192.168.8.1:21 S ==> Ether / IP / TCP 192.168.8.1:21 > 192.168.8.14:20 RA / Padding IP / TCP 192.168.8.14:20 > 192.168.8.1:22 S ==> Ether / IP / TCP 192.168.8.1:22 >...
Please use python and run in IDLE Question 1 Write functions that do the following: i)...
Please use python and run in IDLE Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii)...
How would I get this started: Code a logic program that uses a for loop to...
How would I get this started: Code a logic program that uses a for loop to call your method 5 times successively on the values 1 through 5. (i.e. it would display the val and it’s square…)
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
we are going to focus on basic logic and how you can use logic outside of...
we are going to focus on basic logic and how you can use logic outside of the classroom. Unfortunately, many of our daily interactions include logical errors. Respond to the following prompts in a minimum of 175 words: Consider a recent interaction you have had with a co-worker or item that you saw in the media that might have included logical errors. Share the example as well as the logical errors that are present in the example. Be sure to...
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get...
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get the error: ...could not start SASL... no mechanism available: unable to find a callback: 2"
If I had a software company, what would be a hazard risk one that I can...
If I had a software company, what would be a hazard risk one that I can cover with a common business commercial package policy ? How would I use a decision tree to make a decision about how to treat the hazard risk.
Use python Only can use if statement and loop, that's professor's requirement I have no idea...
Use python Only can use if statement and loop, that's professor's requirement I have no idea how to do that without class Building Entrance Tracker Due to Covid-19, we can allow only 5 guests to our building at a time. Our task is to write a program that helps the entrance staff to keep track of guest entries to the building. Feature 1 (40 points): Each guest must sign in upon entry into the building. If the number of guests...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT