I want to get an integer from the user in each loop and add them. If the user presses q key I want the loop to end immediately without pressing enter and print the total.
!pip install keyboard
import keyboard
total = 0
while True:
if keyboard.is_pressed('q'):
break
x = int(input("Enter a number: "))
total += x
print(total)
I tried this but I got an assertion error, detailed as follows:
AssertionError
Traceback (most recent call last)
<ipython-input-14-e1e12bbc6dc8> in <module>()
3 total = 0
4 while True:
----> 5 if keyboard.is_pressed('q'):
6 break
7 x = int(input("Enter a number "))
5 frames
/usr/local/lib/python3.7/dist-packages/keyboard/_nixcommon.py in aggregate_devices(type_name)
166
167 # If no keyboards were found we can only use the fake device to send keys.
--> 168 assert fake_device
169 return fake_device
170
AssertionError: