-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcubify.py
More file actions
82 lines (69 loc) · 2.51 KB
/
cubify.py
File metadata and controls
82 lines (69 loc) · 2.51 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
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
def cubify(s):
'''
Turns a string into a cube, like this (for the word "star")
RATS
A TT
T A A
STAR R
T A A
A TT
RATS
'''
# Advanced crash prevention techniques
if (len(s) == 0):
return ""
# Initialize blank string
result = ""
# Step 1. The top horizontal line: It's (len(s) - 1) spaces, followed by s backwards with a space between each letter.
result += " " * (len(s) - 1)
# lol this line
# Basically it replaces all the ""s with a space and reverses the string. But that includes the blank before the first char, so we have to snip it out.
result += s.replace("", " ")[::-1][1:]
result += "\n"
# Step 2. The diagonals leading to the middle horizontal line: For each line number x from the top (i.e. the step 1 line is line 1), it's generated by
# (len(s) - x) spaces + xth last char + (len(s) - 2) * 2 spaces + xth char + (x - 2) spaces + xth char
# repeated (len(s) - 2) times.
for i in range(2, len(s)):
result += " " * (len(s) - i)
result += s[-1 * i]
result += " " * ((len(s) * 2) - 3)
result += s[i - 1]
result += " " * (i - 2)
result += s[i - 1]
result += "\n"
# Step 3. The middle horizontal line: The string forwards + (len(s) - 3) spaces + last char
result += s.replace("", " ")[1:]
result += " " * (len(s) - 3)
result += s[-1]
result += "\n"
# Step 4. The diagonals leading to the bottom horizontal line: For reach line number x from the horizontal line, it's generated by
# xth char + ((len(s) * 2) - 3) spaces + xth last char + (len(s) - x - 2) spaces + xth last char
# repeated (len(s) - 2) times.
for i in range(2, len(s)):
result += s[i - 1]
result += " " * ((len(s) * 2) - 3)
result += s[-1 * i]
result += " " * (len(s) - i - 1)
result += s[-1 * i]
result += "\n"
# Step 5. The bottom horizontal line: The string backwards.
result += s.replace("", " ")[::-1][1:]
return result
# badvarnames.jpg
r = True
# Basically code to make cubes over and over
while(r):
s = input("Input a string. \n")
print(cubify(s))
# This is shit code I know
# But I'm lazy
r = None
while (r == None):
r = input("Generate another cube? (Y/N) \n")
if (r == "y" or r == "Y"):
r = True
elif (r == "n" or r == "N"):
r = False
else:
print("Please enter a valid answer.")
r = None