-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.py
41 lines (33 loc) · 1017 Bytes
/
funcs.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
def formatPrint(text):
for i in range(50):
print("\n")
print("Project Dice")
print("------------------------")
print(text)
def rollDice():
import random
input("Press [Enter] to roll")
num = random.randint(1, 6)
print("You rolled a {}".format(num))
return num
def isEven(x):
mod = x % 2
if mod == 0:
return True
else:
return False
def insertLine(lineNum, file, newLine):
f = open(file, "r+") # Opens file in read mode
newLine = "{}\n".format(newLine) # Formats the newline
data = f.readlines() # Stores contents of files as a list
data.insert(lineNum, newLine) # Inserts line in the list
try:
data.pop(5) # Removes the 6th score
except IndexError:
pass
f.close()
f = open(file, "w+") # Purges the file by opening in write mode
f.writelines(data) # Writes list on the file
f.close()
def pause():
input("Press [Enter] to continue")