{"id":71,"date":"2025-05-16T13:54:48","date_gmt":"2025-05-16T13:54:48","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/l_rankins\/?p=71"},"modified":"2025-05-16T13:54:48","modified_gmt":"2025-05-16T13:54:48","slug":"blog-7-something-about-maddness","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/l_rankins\/2025\/05\/16\/blog-7-something-about-maddness\/","title":{"rendered":"BLOG 7: SOMETHING ABOUT MADDNESS"},"content":{"rendered":"\n<p>i made a slot machine<\/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 = 1000<\/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; : 3,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;B&#8221;: 4,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;C&#8221;: 5,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &#8220;D&#8221;: 6<\/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><em>def<\/em> check_winnings(<em>columns<\/em>, <em>lines<\/em>, <em>bet<\/em>, <em>values<\/em>):<\/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(<em>lines<\/em>):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; symbol= <em>columns<\/em>[0][line]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for column in <em>columns<\/em>:<\/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+=<em>values<\/em>[symbol] * <em>bet<\/em><\/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><em>def<\/em> get_slot_machine_spin(<em>rows<\/em>,<em>cols<\/em>,<em>symbols<\/em>):<\/p>\n\n\n\n<p>&nbsp; &nbsp; all_symbols = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; for symbol,symbol_count in <em>symbols<\/em>.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(<em>cols<\/em>):<\/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(<em>rows<\/em>):<\/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><em>def<\/em> print_slot_machine(<em>columns<\/em>):<\/p>\n\n\n\n<p>&nbsp; &nbsp; for row in range(len(<em>columns<\/em>[0])):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for i , column in enumerate(<em>columns<\/em>):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i != len(<em>columns<\/em>) &#8211; 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(column[row], <em>end<\/em> =&#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], <em>end<\/em>=&#8221;&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; print()<\/p>\n\n\n\n<p><em>def<\/em> 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?$ &#8220;)<\/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 should be greater than zero&#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><em>def<\/em> 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(&#8220;Enter No of lines that you want to deposit &#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 valid No 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><em>def<\/em> 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?$ &#8220;)<\/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(<em>f<\/em>&#8220;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><em>def<\/em> spin(<em>balance<\/em>):<\/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; <em>balance<\/em>:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(<em>f<\/em>&#8220;You do not have enough to bet that amount, your current balance id: ${<em>balance<\/em>}&#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(<em>f<\/em>&#8220;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(<em>f<\/em>&#8220;YOU WON ${winnings}&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(<em>f<\/em>&#8220;YOU WON ON LINES: &#8220;, *winning_lines)<\/p>\n\n\n\n<p>&nbsp; &nbsp; return winnings &#8211; total_bet<\/p>\n\n\n\n<p><em>def<\/em> 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(<em>f<\/em>&#8220;Current balance is ${balance}&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; answer=input(&#8220;Press Enter to play the game(q to quit): &#8220;)<\/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(<em>f<\/em>&#8220;You Left with ${balance}&#8221;)<\/p>\n\n\n\n<p>main()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i made a slot machine import random MAX_LINES = 3 MAX_BET = 1000 MIN_BET = 1 ROWS = 3 COLS [&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-71","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/71","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=71"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":72,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/71\/revisions\/72"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}