Executing 2 lines at the same time - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Executing 2 lines at the same time (/thread-14885.html) |
Executing 2 lines at the same time - SheeppOSU - Dec-22-2018 Hi I am trying to execute two lines at the same time. The lines are shown below. Either that or I need it to stop the option to input an answer after 3 seconds on line 24. Thankyou! import random import time Number_0_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] Number_1_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] variable = 0 print('You have 3 seconds to answer each question') time.sleep(3) while True: #This needs to time.sleep(1) #Run While variable = variable + 1 #11 - 31 runs for x in range(0,10): print('Ready...') time.sleep(1) print('Set...') time.sleep(1) print('Go!!!') time.sleep(1) Number_0 = random.choice(Number_0_list) Number_1 = random.choice(Number_1_list) print(Number_0, '*', Number_1) Answer = Number_0 * Number_1 variable_record = variable while variable_record == variable_record + 3: InputAnswer = input("Answer Here: ") print(Answer) print('Did you get it right?') time.sleep(2) print("Now let's do it again") time.sleep(2) print('Ready for the next one?') time.sleep(2) RE: Executing 2 lines at the same time - stullis - Dec-22-2018 You need to play around with multithreading. Since variable is referenced in both loops, you should also reading into locks and thread safe data structures. RE: Executing 2 lines at the same time - Gribouillis - Dec-22-2018 I posted yesterday a code snippet to ask for data with timeout in a console application. I think you can use this snippet for your case. |