Updated to make script write file to card.txt

This commit is contained in:
Tamservo 2023-11-06 20:05:00 -05:00
parent 8f2018b585
commit 175176be6e

View File

@ -43,38 +43,52 @@ ROWS = 5
# We will pull values for the bingo squares from here. # We will pull values for the bingo squares from here.
# A 'string' is a series of characters enclosed in quotes # A 'string' is a series of characters enclosed in quotes
squares = [ squares = [
"Proposal!", "Santa vists",
"Secret Revealed!", "Lead is royalty",
"Christmas Party", "Gingerbread",
"Mistletoe!", "Empty coffee cups",
"Unexpected Small Town Visit", "Hot chocolate",
"Leads are Trapped Together", "Confession of a lie or mistake",
"Lead Who Works as Baker or Florist", "Evil developers",
"Last Minute Rescue", "Mistletoe!",
"Amicable Break Up", "Saving a landmark",
"Mistaken Identity", "Interrupted smooch",
"Christmas-Themed Character or Town Name", "Fake relationship",
"Green Sweater", "Lead who works in real estate",
"A Contest", "Big romantic gesture",
"Surprise Relative", "Secret identity",
"Sparkling Wine", "Unexpected visitor",
"Snippy Comment about Lack of Kids", "Not a couple mistaken as a couple",
"Someone Gets a Second Chance", "Untrustworthy person in a suit",
"Cute Moppet", "US Flag",
"Giant Candy Cane", "Literal fall into someone's arms",
"Christmas Miracle", "Someone returns to hometown",
"Christmas Tree or Lights Lighting", "Christmas market",
"LGBTQ Character", "Snowstorm",
"Neglectful OG Love Interest", "Friends to lovers",
"Meet Cute!", "Christmas wedding",
"Fainting or Feeling Sick", "Pregnant!",
"BIPOC Person has a Lead Role", "Family heirloom",
"Christmas Dance", "Living in home you can't afford",
"Inappropriate High Heels or Outfit", "Charity event",
"We Should Have Had Sex but Halmark", "Homemade decorations",
"Santa Visit", "Someone gets a promotion",
"Lead Who Works in Marketing or Event Planning", "Unreasonable deadline",
"Love Interest is Uber Wealthy or Royalty" "Flirty outdoor winter activity",
"Prevented from attending or staying at event",
"Breakup",
"Failed romantic gesture",
"Lead who owns a business",
"Real snow",
"Contract or business deal",
"Red coat",
"A misunderstanding",
"Giant, shiny big city offices",
"Change of heart",
"Empty gift boxes or bags",
"Snow falling",
"Empty coffee cups",
"Precocious child",
] ]
@ -83,72 +97,86 @@ squares = [
# If there are no parameters, use an empty () # If there are no parameters, use an empty ()
# functions make it easier to do the same thing over again. # functions make it easier to do the same thing over again.
def print_dash_line (): # Python uses indentation to organize code def make_dash_line (): # Python uses indentation to organize code
print("+", end='') output = "+"
for i in range(SQUARES_PER_ROW): for i in range(SQUARES_PER_ROW):
for j in range(SQUARE_LENGTH): for j in range(SQUARE_LENGTH):
print("-", end='') output += "="
print("+", end='') output += "+"
print("\n",end='') # Here we are still inside the function, but outside output += "\n" # Here we are still inside the function, but outside
# the loop return output # the loop
# This function will take the row of the square, and the string and # This function will take the row of the square, and the string and
# print out the padded section of the string for this line # print out the padded section of the string for this line
def get_square_text(row, s): def get_square_text(row, s):
wrapped_strings = textwrap.wrap(str(s),width=SQUARE_LENGTH) wrapped_strings = textwrap.wrap(str(s),width=SQUARE_LENGTH)
output = ""
print("|", end='')
string_section = "test string".center(SQUARE_LENGTH)
if row < len(wrapped_strings): if row < len(wrapped_strings):
string_section = wrapped_strings[row] string_section = wrapped_strings[row]
else: else:
string_section = " " string_section = " "
return string_section.center(SQUARE_LENGTH)
return output + string_section.center(SQUARE_LENGTH)
# The function print_row will take 5 strings and print a bingo row # The function print_row will take 5 strings and print a bingo row
def print_row (row_strings): def make_row (row_strings):
# each square will be 5 rows high and 12 chars across. We can adjust # each square will be 5 rows high and 12 chars across. We can adjust
# this to make the layout better # this to make the layout better
output = ""
for i in range(SQUARE_HEIGHT): for i in range(SQUARE_HEIGHT):
#For each line in the row, get the part of the string #For each line in the row, get the part of the string
#Which will be printed on this line #Which will be printed on this line
for j in range(SQUARES_PER_ROW): for j in range(SQUARES_PER_ROW):
print( get_square_text(i, row_strings[j]), end='') output += "|"
output += get_square_text(i, row_strings[j])
print("|") output += "|\n"
return output
# At random, pull values from "squares" and print out 5 rows of bingo card def print_card():
selected = [-1] # At random, pull values from "squares" and print out 5 rows of bingo card
for i in range(ROWS): selected = [-1]
print_dash_line() output = ""
for i in range(ROWS):
output += make_dash_line()
# get 5 new picks # get 5 new picks
picks = [] picks = []
for j in range( SQUARES_PER_ROW ): for j in range( SQUARES_PER_ROW ):
# If we have the center square, set "Free" # If we have the center square, set "Free"
if i == 2 and j == 2: if i == 2 and j == 2:
picks.append("Free") picks.append("Free")
continue continue
# Keep picking a number until we get one we haven't picked yet # Keep picking a number until we get one we haven't picked yet
pick = -1 pick = -1
while pick in selected: while pick in selected:
pick = random.randrange(0,len(squares)) pick = random.randrange(0,len(squares))
# Record that we have picked this item # Record that we have picked this item
selected.append(pick) selected.append(pick)
picks.append(squares[pick]) picks.append(squares[pick])
# Now print the row with those picks # Now print the row with those picks
print_row(picks) output += make_row(picks)
# Print last bottom line # Print last bottom line
print_dash_line() output += make_dash_line()
return output
card = print_card()
with open("card.txt", "w") as f:
f.write(card)
print("Bingo card has been created as card.txt")
input("Enter to exit...")