{"id":81,"date":"2025-09-26T15:28:06","date_gmt":"2025-09-26T15:28:06","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/l_rankins\/?p=81"},"modified":"2025-09-26T15:28:06","modified_gmt":"2025-09-26T15:28:06","slug":"post-10-gladness-is-maddness","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/l_rankins\/2025\/09\/26\/post-10-gladness-is-maddness\/","title":{"rendered":"POST 10: GLADNESS IS MADDNESS"},"content":{"rendered":"\n<p>Today I made a Slot machine with a tutorial <\/p>\n\n\n\n<p>import random<\/p>\n\n\n\n<p>MAX_LINES = 3<\/p>\n\n\n\n<p>MAX_BET = 100<\/p>\n\n\n\n<p>MIN_BET = 1<\/p>\n\n\n\n<p>ROWS = 3<\/p>\n\n\n\n<p>COLS = 3<\/p>\n\n\n\n<p>symbol_count = {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;A&#8221;: 2,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;B&#8221;: 4,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;C&#8221;: 6,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;D&#8221;: 8<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>symbol_value = {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;A&#8221;: 5,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;B&#8221;: 4,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;C&#8221;: 3,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;D&#8221;: 2<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>this is the symbols and values for the memory<\/p>\n\n\n\n<p>def check_winnings(columns, lines, bet, values):<\/p>\n\n\n\n<p>&nbsp; &nbsp; winnings = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; winning_lines = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; for line in range(lines):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; symbol = columns[0][line]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for column in columns:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; symbol_to_check = column[line]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if symbol != symbol_to_check:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; winnings += values[symbol] * bet<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; winning_lines.append(line + 1)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return winnings, winning_lines<\/p>\n\n\n\n<p>this checks how much you will get from winning<\/p>\n\n\n\n<p>ef get_slot_machine_spin(rows, cols, symbols):<\/p>\n\n\n\n<p>&nbsp; &nbsp; all_symbols = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; for symbol, symbol_count in symbols.items():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for _ in range(symbol_count):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; all_symbols.append(symbol)<\/p>\n\n\n\n<p>&nbsp; &nbsp; columns = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; for _ in range(cols):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; column = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; current_symbols = all_symbols[:]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for _ in range(rows):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = random.choice(current_symbols)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current_symbols.remove(value)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column.append(value)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; columns.append(column)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return columns<\/p>\n\n\n\n<p>this is the thing that chooses the Symbols and such<\/p>\n\n\n\n<p>def print_slot_machine(columns):<\/p>\n\n\n\n<p>&nbsp; &nbsp; for row in range(len(columns[0])):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for i, column in enumerate(columns):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i != len(columns) &#8211; 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(column[row], end=&#8221; | &#8220;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(column[row], end=&#8221;&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; print()<\/p>\n\n\n\n<p>this one prints the columns obviously<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>def deposit():<\/p>\n\n\n\n<p>&nbsp; &nbsp; while True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; amount = input(&#8220;What would you like to deposit? $&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if amount.isdigit():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; amount = int(amount)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if amount &gt; 0:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Amount must be greater than 0.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Please enter a number.&#8221;)<\/p>\n\n\n\n<p>\u00a0 \u00a0 return amount <\/p>\n\n\n\n<p>this is for how much you pay to spin and such<\/p>\n\n\n\n<p>def get_number_of_lines():<\/p>\n\n\n\n<p>&nbsp; &nbsp; while True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; lines = input(<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;Enter the number of lines to bet on (1-&#8221; + str(MAX_LINES) + &#8220;)? &#8220;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if lines.isdigit():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lines = int(lines)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 1 &lt;= lines &lt;= MAX_LINES:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Enter a valid number of lines.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Please enter a number.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return lines<\/p>\n\n\n\n<p>how much you bet on the lines<\/p>\n\n\n\n<p>def get_bet():<\/p>\n\n\n\n<p>&nbsp; &nbsp; while True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; amount = input(&#8220;What would you like to bet on each line? $&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if amount.isdigit():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; amount = int(amount)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if MIN_BET &lt;= amount &lt;= MAX_BET:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221;Amount must be between ${MIN_BET} &#8211; ${MAX_BET}.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;Please enter a number.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return amount<\/p>\n\n\n\n<p>this is for betting<\/p>\n\n\n\n<p>def spin(balance):<\/p>\n\n\n\n<p>&nbsp; &nbsp; lines = get_number_of_lines()<\/p>\n\n\n\n<p>&nbsp; &nbsp; while True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; bet = get_bet()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; total_bet = bet * lines<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if total_bet &gt; balance:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f&#8221;You do not have enough to bet that amount, your current balance is: ${balance}&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; f&#8221;You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet}&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; slots = get_slot_machine_spin(ROWS, COLS, symbol_count)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print_slot_machine(slots)<\/p>\n\n\n\n<p>&nbsp; &nbsp; winnings, winning_lines = check_winnings(slots, lines, bet, symbol_value)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(f&#8221;You won ${winnings}.&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(f&#8221;You won on lines:&#8221;, *winning_lines)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return winnings &#8211; total_bet<\/p>\n\n\n\n<p>this one pays out<\/p>\n\n\n\n<p>def main():<\/p>\n\n\n\n<p>&nbsp; &nbsp; balance = deposit()<\/p>\n\n\n\n<p>&nbsp; &nbsp; while True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221;Current balance is ${balance}&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; answer = input(&#8220;Press enter to play (q to quit).&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if answer == &#8220;q&#8221;:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; balance += spin(balance)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(f&#8221;You left with ${balance}&#8221;)<\/p>\n\n\n\n<p>main()<\/p>\n\n\n\n<p>this one shows how much you have left<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I made a Slot machine with a tutorial import random MAX_LINES = 3 MAX_BET = 100 MIN_BET = 1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}