Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading as t
- def square(num):
- print(f"Square of {num} is {num**2}")
- def cube(num):
- print(f"Cube of {num} is {num**3}")
- number = int(input("Enter a number to find square and cube:"))
- thread1 = t.Thread(target=square,args=(number,))
- thread2 = t.Thread(target=cube,args=(number,))
- thread1.start()
- thread2.start()
- thread1.join()
- thread2.join()
- print("Both threads have executed successfully")
- import threading as t
- import time
- def print_numbers():
- for i in range(1,6):
- print(f"Number: {i}")
- time.sleep(1)
- def print_alphabets():
- for char in 'ABCDE':
- print(f"Alphabet: {char}")
- time.sleep(1)
- thread1 = t.Thread(target=print_numbers)
- thread2 = t.Thread(target=print_alphabets)
- thread1.start()
- thread2.start()
- thread1.join()
- thread2.join()
- print("Both threads have executed successfully")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement