-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_data_generator.py
More file actions
43 lines (34 loc) · 1.13 KB
/
random_data_generator.py
File metadata and controls
43 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
'''Keystone Learning | Paul Lack
Generate a file with a user-defined number of lines. Each line will
consist of random sequences of three, four, or five characters. The
user is allowed to insert a non-random word into the file at an un-
known location. The file can then be used to write a Python script to
find the non-random word'''
import string
import random
CHARS = tuple(string.ascii_lowercase
+ string.ascii_uppercase
+ string.digits
+ string.punctuation)
word_length = (3, 4, 5)
def word_builder():
word = ''
for i in range(random.choice(word_length)):
word = word + random.choice(CHARS)
return word
def line_builder():
line = ''
for i in range(10):
line = line + word_builder() + ' '
return line
def write_line(file_length):
for i in range(file_length):
line = line_builder()
with open('big_file.txt', 'a') as f:
print(line, file=f)
def main():
file_length = int(input('How many lines should be in the file? >>> '))
write_line(file_length)
if __name__ == "__main__":
main()