1from time import sleep
2import sys
3
4string = "The Battle Cats For Life" # Whatever string you want
5
6for letter in string:
7 sleep(0.01) # In seconds
8 sys.stdout.write(letter)
9 sys.stdout.flush()
1# Iterator
2def infinite_stream(start: int) -> Iterator[int]:
3 while True:
4 yield start
5 start += 1
6
7# Generator
8def infinite_stream(start: int) -> Generator[int, None, None]:
9 while True:
10 yield start
11 start += 1
12
1How to test Typing Speed using Python?
2
3Difficulty Level : Basic
4Last Updated : 05 Sep, 2020
5Prerequisites: Python GUI – tkinter
6
7#We will create a program test the typing speed of the user with a basic GUI application using Python language. Here the Python libraries like Tkinter and Timeit are used for the GUI and Calculation of time for speed testing respectively. Also, the Random function is used to fetch the random words for the speed testing calculation. Following command is used to install the above-mentioned libraries:
8
9pip install tkintertable
10pip install pytest-timeit
11Firstly, all the libraries are imported that are installed as mentioned above, and using the bottom-up approach the programming for testing the typing speed using python is created.
12
13Below is the implementation.
14
15
16
17# importing all libraries
18from tkinter import *
19from timeit import default_timer as timer
20import random
21
22# creating window using gui
23window = Tk()
24
25# the size of the window is defined
26window.geometry("450x200")
27
28x = 0
29
30# defining the function for the test
31def game():
32 global x
33
34 # loop for destroying the window
35 # after on test
36 if x == 0:
37 window.destroy()
38 x = x+1
39
40 # defining function for results of test
41 def check_result():
42 if entry.get() == words[word]:
43
44 # here start time is when the window
45 # is opened and end time is when
46 # window is destroyed
47 end = timer()
48
49 # we deduct the start time from end
50 # time and calculate results using
51 # timeit function
52 print(end-start)
53 else:
54 print("Wrong Input")
55
56 words = ['programming', 'coding', 'algorithm',
57 'systems', 'python', 'software']
58
59 # Give random words for testing the speed of user
60 word = random.randint(0, (len(words)-1))
61
62 # start timer using timeit function
63 start = timer()
64 windows = Tk()
65 windows.geometry("450x200")
66
67 # use lable method of tkinter for labling in window
68 x2 = Label(windows, text=words[word], font="times 20")
69
70 # place of labling in window
71 x2.place(x=150, y=10)
72 x3 = Label(windows, text="Start Typing", font="times 20")
73 x3.place(x=10, y=50)
74
75 entry = Entry(windows)
76 entry.place(x=280, y=55)
77
78 # buttons to submit output and check results
79 b2 = Button(windows, text="Done",
80 command=check_result, width=12, bg='grey')
81 b2.place(x=150, y=100)
82
83 b3 = Button(windows, text="Try Again",
84 command=game, width=12, bg='grey')
85 b3.place(x=250, y=100)
86 windows.mainloop()
87
88
89x1 = Label(window, text="Lets start playing..", font="times 20")
90x1.place(x=10, y=50)
91
92b1 = Button(window, text="Go", command=game, width=12, bg='grey')
93b1.place(x=150, y=100)
94
95# calling window
96window.mainloop()
97Output:
98
99Video Player
100
10100:00
10200:15
103
104
105In the above code, we first create the speed testing window using Tkinter. The function is defined for calculating and printing the correct output after the user input. A specific list of words is provided to the user to type and test the speed of typing. For that, we provide a list of words and generate them with the random function.
1from collections.abc import Iterable
2
3def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:
4 for var in vars:
5 var.set(0)
6
1# For collections, the name of the type is capitalized, and the
2# name of the type inside the collection is in brackets
3x: List[int] = [1]
4x: Set[int] = {6, 7}
5
6# For simple built-in types, just use the name of the type
7x: int = 1
8x: float = 1.0
9x: bool = True
10x: str = "test"
11x: bytes = b"test"