Question

During the covid-19 pandemic banks in Turkey started to allow only a few numbers of customers...

During the covid-19 pandemic banks in Turkey started to allow only a few numbers of customers to be present in the branch. Assume that 20 customers will visit bank and perform some operations with their bank accounts. The bank only allows 2 customers at a time. You should implement this scenario using 2 threads and a main thread (3 threads in total). Simulate that each customer will spend some random time between 5 – 10 seconds in branch. You should output a message when the customer enters and leaves the branch and also while performing an operation with the sufficient customer id. Your code should have outputs pretty much like the following example.

Ex:

Customer 1 entered the bank.

Customer 1 performing an operation.

Customer 2 entered the bank.

Customer 2 performing an operation.

Customer 1 left the bank.

Customer 3 entered the bank.

Customer 3 started performing an operation.

Customer 3 left the bank.

Customer 2 left the bank.

Customer 4 entered the bank.

Customer 5 entered the bank.

Customer 4 started an operation.

Customer 5 started an operation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


aux 1 - Q te aux 1.py Pycharm Projects untitled pythonjs te aux1.py ht_ml.py te ht_ml1.py teht_ml2.py import threading import

 import threading import time import random customerStatus = [] for i in range(0, 20): customerStatus.append(0) # customerStatus=0: customer's banking operation is pending # customerStatus=1: customer's banking operation is completed class Counter(object): # for maintaining mutual exclusion def __init__(self, start=0): self.lock = threading.Lock() def goInsideBank(self,pointer): while (pointer<20): self.lock.acquire() #Waiting for a lock try: #Acquired a lock if (pointer >= 20): return while (customerStatus[pointer] != 0): # checking current customer's status pointer = pointer + 1 if (pointer >= 20): return if (pointer >= 20): return customerStatus[pointer]=1 # changing the current customer's status from 0 to 1 because # he is now allowed to enter into the bank print("Customer ", pointer, " entered the bank") s=random.uniform(5,10) # waiting for a random number of seconds between 5-10 print("Customer ", pointer, " performing an operation for ",s," seconds") time.sleep(s) print("Customer ", pointer, " left the bank --Thread ID: ",threading.get_ident()) finally: #Released a lock self.lock.release() def banking(c): for i in range (0,20): c.goInsideBank() print('Done',i) if __name__ == '__main__': counter1 = Counter() counter2 = Counter() t = threading.Thread(target=counter1.goInsideBank, args=(0,)) # creating thread 1 t.start() t2 = threading.Thread(target=counter2.goInsideBank, args=(0,)) # creating thread 2 t2.start() main_thread = threading.currentThread() # main thread for t in threading.enumerate(): if t is not main_thread: # waiting for both the threads to finish t.join() print('FINISHED')
Add a comment
Know the answer?
Add Answer to:
During the covid-19 pandemic banks in Turkey started to allow only a few numbers of customers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Covid-19 pandemic forced more than a third of the planet's population under some form of...

    The Covid-19 pandemic forced more than a third of the planet's population under some form of restriction resulting in grave impact on manufacturing firms. Due to the severity of the pandemic, many companies are facing significant operational, financial and liquidity challenges”. [1] Analysts have identified the following as some of the key factors that give rise to these challenges: . Collapse of demand due to locked-down imposed by the government. • Supply shortages and increased prices - Until affected factories...

  • The Covid-19 pandemic forced more than a third of the planet's population under some form of...

    The Covid-19 pandemic forced more than a third of the planet's population under some form of restriction resulting in grave impact on manufacturing firms. Due to the severity of the pandemic, many companies are facing significant operational, financial and liquidity challenges”. [1] Analysts have identified the following as some of the key factors that give rise to these challenges: . Collapse of demand due to locked-down imposed by the government. • Supply shortages and increased prices - Until affected factories...

  • Question 1: (20) The Covid-19 pandemic and the lockdown that followed have served as multiple shocks...

    Question 1: (20) The Covid-19 pandemic and the lockdown that followed have served as multiple shocks to the South African economy. The initial 5-week lockdown limited mobility of people and the availability of goods and services, leading to contractions in aggregate demand and supply. Policymakers have responded with expansionary fiscal and monetary policy. The government has implemented a R500bn support package and the Reserve Bank has reduced the repo rate and extended liquidity in the bond market. Apply any, or...

  • BYP7-3 Banks charge customers fees of up to $40 per cheque for writing "bounced" cheques; that...

    BYP7-3 Banks charge customers fees of up to $40 per cheque for writing "bounced" cheques; that is cheques that exceed the balance in the account. It has been estimated that processing bounced cheques costs a bank roughly $5 per cheque. Thus, the profit margin on a bounced cheque is very high. Some banks process cheques from largest amount to smallest. By doing this, they maximize the number of cheques that bounce if a customer overdraws an account. Ethics Case Instructions...

  • Exercise 10-30 Activity-Based Costing of Customers (LO 10-3, 4) Rock Solid Bank and Trust (RSB&am...

    Exercise 10-30 Activity-Based Costing of Customers (LO 10-3, 4) Rock Solid Bank and Trust (RSB&T) offers only checking accounts. Customers can write checks and use a network of automated teller machines. RSB&T earns revenue by investing the money deposited; currently, it averages 6.20 percent annually on its investments of those deposits. To compete with larger banks, RSB&T pays depositors 0.50 percent on all deposits. A recent study classified the bank’s annual operating costs into four activities: Activity Cost Driver Cost...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • e-Business Strategy and Models in Banks : Case of Citibank E-business strategy in Citibank: Banks today...

    e-Business Strategy and Models in Banks : Case of Citibank E-business strategy in Citibank: Banks today are up-to-date with both the pros and cons of the internet. They are aware of the opportunities and threats that are associated with the Web. Not a single traditional bank is brave enough to face investment analysts without an Internet strategy. But even a very thoughtful approach to the Web may do no good to the company/ organization. The main purpose behind launching online...

  • Question 1 6 pts (TCO 1) Good system requirement are: Unambiguous - Has one, and only...

    Question 1 6 pts (TCO 1) Good system requirement are: Unambiguous - Has one, and only one, meaning Detailed - All significant capabilities and attributes are addressed and terms are fully defined. Verifiable - Must have some method that determines whether the requirements have been satisfied All of the above None of the above Question 2 6 pts (TCO 1) A software engineering process (SEP), also known as a software development process, defines the ______ of developing software. who, what,...

  • Hi, Kindly assist with my project management assignment below using the attached case study Question 1 Update the project charter for the remainder of the project in response to Adams’ memo (lines 241...

    Hi, Kindly assist with my project management assignment below using the attached case study Question 1 Update the project charter for the remainder of the project in response to Adams’ memo (lines 241 through 246). Question 2 Prepare a plan for the remainder of the project in response to Adams’ memo (lines 241 through 246). Your answers to the above will be assessed in terms of the level of communication displayed, the insights and inferences drawn, and your ability to...

  • 3. An examination of the cash activities during the year shows the following Date 7/1 7/15...

    3. An examination of the cash activities during the year shows the following Date 7/1 7/15 1,900 7/22 ock 7/39 8/1 8/10 8/12 9/21 10/11 12/15 GREAT ADVENTURES Cash Account Record July 1, 2021, to December 5, 2021 Cash Receipte Car Disbursemente Amount Date Dese Stock sale $ 30,000/ Trance Clinic receipt 1,600 1/2 162 Legal Fees Clinie receipte 2.760 / De Advertising Clinie receipte 3.600 90 101 Bikes Borrowing 38,000 7724 be Mdvertising Clinio receipts 5.100 4/4 104 Kayaks...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT