{"id":455,"date":"2022-10-04T22:27:24","date_gmt":"2022-10-04T22:27:24","guid":{"rendered":"http:\/\/yesrenee.com\/?p=455"},"modified":"2023-08-28T18:06:02","modified_gmt":"2023-08-28T18:06:02","slug":"python-lottery-explanation","status":"publish","type":"post","link":"https:\/\/yesrenee.com\/?p=455","title":{"rendered":"&#8216;Python Lottery&#8217; Explanation"},"content":{"rendered":"\n<p>Key: <em>italic<\/em> is for python functions and <strong>bold<\/strong> is for variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># deciding if the lottery is a benefit\r\n\r\nimport random\r\n\r\nMyChoice=&#91;12, 33, 4, 6, 46, 29, 50]\r\n\r\nbalance = 1000 # I will spend this much money for the lottery\r\nmoneyIWon = 0\r\ntimesPlayed = 0\r\nwhile balance >= 5:\r\n    timesPlayed += 1\r\n    balance -= 5\r\n    result = &#91;]\r\n    while len(result) &lt; 7:\r\n        thisResult = random.randint(1, 50)\r\n        if thisResult not in result:\r\n            result.append(thisResult)\r\n\r\n    myGuess = 0\r\n    for i in MyChoice:\r\n        if i in result:\r\n            myGuess += 1\r\n\r\n    if myGuess == 3:\r\n        balance += 5\r\n        moneyIWon += 5\r\n        print(\"I won 5 dollars!\")\r\n    elif myGuess == 4:\r\n        balance += 20\r\n        moneyIWon += 20\r\n        print(\"I won 20 dollars!\")\r\n\r\n    elif myGuess == 5:\r\n        balance += 106\r\n        moneyIWon += 106\r\n        print(\"I won 106 dollars!\")\r\n\r\n    elif myGuess == 6:\r\n        balance += 5351\r\n        moneyIWon += 5351\r\n        print(\"I won 5351 dollars!\")\r\n\r\n    elif myGuess == 7:\r\n        balance += 70000000\r\n        moneyIWon += 70000000\r\n        print(\"I won 70000000 dollars! Oh, my!\")\r\n        break\n\r\n\r# conclusion\n\nprint('I tried',timesPlayed,'times, spent',timesPlayed*5,'dollars and the money I have left is', balance, 'dollars.')\r\nprint('I got', moneyIWon, 'dollars by buying lottery tickets, but my profit was spent.')\r\n\n# end of code<\/code><\/pre>\n\n\n\n<p>First: The <em>#<\/em> signs represent a comment. Comments can help someone understand the code. It&#8217;s like a silvery ghost. <em>import random<\/em> indicates that random will be used in this code to help choose random numbers for the lottery. When you don&#8217;t use this, <span class=\"has-inline-color has-cyan-bluish-gray-color\"><em>import random<\/em> <\/span>is gray. Alright, <strong>MyChoice<\/strong> is a set of numbers I randomly picked. It doesn&#8217;t have to be exactly that set of numbers, but I chose that set. You&#8217;ll see why soon&#8230;<\/p>\n\n\n\n<p><em>Balance<\/em> tells the money I have. Right now I pretend I have $1000. You may change the value into whatever you wish-68, 53302, 1, 20.43, 3.14159265358979323, 100000009&#8230; <strong>MoneyIWon<\/strong> means, well, money <span class=\"has-inline-color has-vivid-purple-color\">you<\/span> won. <strong>TimesPlayed<\/strong> is of course the times I played the lottery. And just about 5 coins will buy you a ticket. So, while you can afford a ticket <em>(while balance >= 5:)<\/em>, you play 1 more time, and you add one to your <strong>timesPlayed<\/strong> bag. And you lose your precious 5 coins. (Perhaps cash!) So the <strong>balance <\/strong>bag is subtracted by 5. <\/p>\n\n\n\n<p><strong>Result<\/strong>, that&#8217;s the true lottery numbers. Like, if your guess is 34, 45, 1, 39, 12, 21, and 7, but the answer is 43, 50, 3, 9, 35, 31, and 49, then that is <strong>result<\/strong>. Right now, this list is plain. You pick 7 numbers. When you have picked these 7, this code stops. Now, the <em>random.randint(1, 50)<\/em> shows the <em>random<\/em> way- it picks a number from 1 to 50 for <strong>result<\/strong>.<\/p>\n\n\n\n<p><strong>MyGuess<\/strong> says how many numbers I guessed correct. Reading the code, if I get 3 correct I get 5 dollars, which can help me get a large box of glazed treats. If I get 4 correct, I get 20 dollars, which can buy me a warm winter coat. And $106 can buy me a really nice gift for someone. $5351, well, that can buy a simple phone, right? But then, after that, I can buy 10 boxes of treats, 10 winter coats, 10 really nice gifts, 10 simple phones, and still have money for a new mansion and furniture! Okay. Back from the break. <\/p>\n\n\n\n<p>For the conclusion.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print('I tried',timesPlayed,'times, spent',timesPlayed*5,'dollars and the money I have left is', balance, 'dollars.')\r\nprint('I got', moneyIWon, 'dollars by buying lottery tickets, but my profit was spent.')<\/code><\/pre>\n\n\n\n<p>We draw the conclusion. If you run this code, your conclusion will be something like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>I tried 215 times, spent 1075 dollars and the money I have left is 0 dollars.\r\nI got 75 dollars by buying lottery tickets, but my profit was spent.<\/code><\/pre>\n\n\n\n<p>We tell Python to print out how many times we tried to win money from the lottery. Next, we calculate how much money we spent. And we are informed how much money you got and the very final result. But why <strong>timesPlayed<\/strong> X 5? Well, try to remove the <span class=\"has-inline-color has-luminous-vivid-orange-color\">X 5<\/span>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Key: italic is for python functions and bold is for variables. First: The # signs represent a comment. Comments can help someone understand the code. It&#8217;s like a silvery ghost. import random indicates that random will be used in this code to help choose random numbers for the lottery. When you don&#8217;t use this, import [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[19],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-daily","tag-python-programming"],"_links":{"self":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455"}],"version-history":[{"count":1,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}