-
Notifications
You must be signed in to change notification settings - Fork 1
/
agama.py
93 lines (74 loc) · 2.1 KB
/
agama.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# stellagama.py
# A module with various useful functions by Omer Golan-Joel
# This is open source code, feel free to use it for any purpose
# contact me at [email protected]
# import modules
import random
import os
import platform
# functions
def yn():
query = True
while query:
answer = input("Y/N: ")
if answer.lower() == "y":
return True
break
if answer.lower() == "n":
return False
break
else:
print("Invalid Answer")
def dice(n, sides):
die = 0
roll = 0
while die < n:
roll = roll + random.randint(1, sides)
die += 1
return roll
def pseudo_hex(num):
num = int(num)
code = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q",
"E", "S", "T", "U", "V", "W", "X", "Y", "Z"]
num = code[num]
return num
def current_dir():
if platform.system() == "Windows":
directory = os.listdir(".\\")
else:
directory = os.getcwd()
return directory
def check_file_exists(check_file):
if check_file in os.listdir():
file_exists = True
else:
file_exists = False
return file_exists
def savefile(extension):
filename = str(input("Please enter file name to save: "))
filecheck = filename + "." + extension
if check_file_exists(filecheck):
print(" ")
print("File already exists. Overwrite?")
overwrite = yn()
if overwrite:
pass
if not overwrite:
filename = input("Please enter new file name to generate: ")
filename = filename + "." + extension
return filename
def clear_screen():
if platform.system() == "Windows":
os.system('cls')
else:
os.system('clear')
def random_line(filename):
with open(filename, "r") as line_list:
line = random.choice(line_list.readlines())
line = line.strip()
return line
def list_stringer(input_list):
output_list = []
for item in input_list:
output_list.append(str(item))
return ' '.join(output_list)