Transposed wheels in machine str

This commit is contained in:
2026-02-03 18:46:51 +10:00
parent 13eb629a16
commit c6ee83e51a

View File

@@ -18,16 +18,29 @@ class SlotMachine():
def __str__(self):
string = ""
for wheel in self.wheels:
string += str(wheel) + "\n"
# Create an empty matrix with the sole purpose of transposing it
matrix = [[],[],[]]
for i, wheel in enumerate(self.wheels):
for icon in wheel.icons:
matrix[i].append(icon)
# Use Zip function to aggregate unpacked matrix (*matrix unpacks it)
matrix = zip(*matrix)
for row in matrix:
for icon in row:
string += str(icon) + " "
string += "\n"
return string
def main():
# machine = SlotMachine()
# print(machine)
# machine.spin(randomness=1)
# print(machine)
machine = SlotMachine()
print(machine)
machine.spin()
print(machine)
pass
if __name__ == "__main__":