610-20 guruh talabasi Sulaymonov Sherzodbek Inomjon o‘g‘li
7-amaliyot.
Dastur kodi:
import time
import threading
def sonning_kvadrati(numbers):
print("Sonlarning kvadratini xisoblash:")
for i in numbers:
time.sleep(0.2)
print('Natija1:', i*i)
def sonning_kubi(numbers):
print("Sonlarning kubini xisoblash:")
for i in numbers:
time.sleep(0.2)
print("Natija2:", i*i*i)
arr = [2, 3, 4, 5]
t = time.time()
t1 = threading.Thread(target=sonning_kvadrati, args=(arr,))
t2 = threading.Thread(target=sonning_kubi, args=(arr,))
t1.start()
t2.start()
t1.join()
t2.join()
#sonning_kvadrati(arr) # dasturni ketma ket bajarilish xolati
#sonning_kubi(arr) # dasturni ketma ket bajarilish xolati
print("Quidagi vaqtda bajarildi:", time.time()-t)
Dastur natijasi:
Do'stlaringiz bilan baham: |