<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matt Stubbs on Medium]]></title>
        <description><![CDATA[Stories by Matt Stubbs on Medium]]></description>
        <link>https://medium.com/@mattstubbs?source=rss-346e56c54027------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VwrFrvTrQVdqsbfg.jpg</url>
            <title>Stories by Matt Stubbs on Medium</title>
            <link>https://medium.com/@mattstubbs?source=rss-346e56c54027------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:17:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mattstubbs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Beginner: Week 4 — Project: Randomness in Games]]></title>
            <link>https://medium.com/@mattstubbs/python-beginner-week-4-project-randomness-in-games-1d297b4c8d07?source=rss-346e56c54027------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d297b4c8d07</guid>
            <dc:creator><![CDATA[Matt Stubbs]]></dc:creator>
            <pubDate>Sun, 31 May 2020 05:16:37 GMT</pubDate>
            <atom:updated>2020-05-31T05:16:37.100Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Beginner: Week 4 — Project: Randomness in Games</h3><h3>Core Concepts (Week 4)</h3><ul><li>Random Module/ python modules in general</li><li>While loops</li><li>Variables/ Lists</li></ul><h3>Overview</h3><p>Randomness is an intrinsic element of life, as well as games. Anything from Pokemon to Chess involves randomness in some way.</p><p>In this project, students will program small games that have some random element and include at least two calls to a function from the Python Random module. At the end of the project, students will combine their games into one large quest.</p><p><strong>Reference: </strong><a href="https://docs.python.org/3/library/random.html"><strong>https://docs.python.org/3/library/random.html</strong></a></p><h3>LESSON STRUCTURE</h3><ul><li><strong>Introduction [5 min]</strong></li><li><strong>While loops: overview [5 min]</strong></li><li><strong>Demonstration of Examples: [5–10 min]</strong></li><li><strong>Free programming time : [30–40 min]</strong></li><li><strong>Run through final game</strong>: [until end of class]</li></ul><h3>Game Examples.. Monty Hall and 1–100 Guess</h3><ol><li>Monty Hall Problem (<a href="https://www.youtube.com/watch?v=AD6eJlbFa2I">https://www.youtube.com/watch?v=AD6eJlbFa2I</a> for the first minute for a Brooklyn99 intro) or <a href="https://en.wikipedia.org/wiki/Monty_Hall_problem">https://en.wikipedia.org/wiki/Monty_Hall_problem</a></li></ol><pre>import random</pre><pre>def monty_hall_game():<br>    door = random.randint(1,3)<br>            <br>    if door == 1:<br>        wrong = (2,3)<br>    elif door == 2:<br>        wrong = (1,3)<br>    elif door == 3:<br>        wrong = (1,2)<br><br>    print(&quot;Hi, welcome to the SV Tesla sweepstakes. My name is Monty Hall. Next to me there are three doors. Behind one of the doors is a new Tesla Cybertruck. Behind the other two are goats. Take a guess! Which door do you think the Tesla is behind?\n<br>Enter: 1, 2, or 3:&quot;)<br>            <br>    choice = int(input(&quot;\t&gt;&gt;&quot;))<br>            <br>    print(&quot;\nThanks for choosing. Now, because I am such a nice guy, I am going to show you a door which has a goat behind it.&quot;)<br>            <br>    if choice == door:<br>        monty_choice = random.choice(wrong)<br>        if monty_choice == wrong[0]:<br>            alternate = wrong[1]<br>        else:<br>            alternate = wrong[0]<br>    elif choice in wrong:<br>        if choice == wrong[0]:<br>            monty_choice = wrong[1]<br>            alternate = door<br>        elif choice == wrong[1]:<br>            monty_choice = wrong[0]<br>            alternate = door<br>  <br>    print(&quot;I reveal... Door number: &quot; + str(monty_choice) + &quot; (is a goat door)&quot;)<br>    <br>    print(&quot;Would you like to change your choice? y/n &quot;)<br>            <br>    choice2 = input(&quot;\t &gt;&gt; &quot;)<br>            <br>    if choice2.lower() == &quot;y&quot;:<br>        choice = alternate<br>                <br>    print(&quot;You have chosen door &quot; + str(choice) + &quot;. Behind this door is.........\n\n&quot;)<br>            <br>    if choice == door:<br>        print(&quot;Tesla Cybertruck! You win!&quot;)<br>                <br>    elif choice in wrong:<br>        print(&quot;A fat, stinking goat!! better luck next time.&quot;)<br>            <br>    print(&quot;Would you like to play again? y or n&quot;)<br>    play = input(&quot;\t &gt;&gt;&quot;).lower()<br>            <br>    if play == &#39;y&#39;:<br>        monty_hall_game()<br>        <br>monty_hall_game()</pre><p>2. Guess a number from 1 to 100. But you only have 7 chances!</p><pre>import random</pre><pre>print(&quot;Welcome to the guessing game of doom. You have to guess my secret number from 1 to 100. And, you only have 7 tries! G00d luck\n\n &quot;)</pre><pre>def guessingGame():<br>    <br>    tries = 7<br>    upper = 100<br>    lower = 1<br>    guess = 7<br>    answer = random.randint(1,100)</pre><pre>while tries &gt; 0:<br>        print(&quot;Guess now!&quot;)<br>        <br>        guess = int(input(&quot;\t &gt;&gt; &quot;))<br>        <br>        if guess == answer:<br>            print(&quot;Congrats, you won the game!!&quot;)<br>            break<br>        <br>        elif guess != answer:<br>            tries -= 1<br>            print(&quot;Wrong guess.. You now have {} tries remaining..&quot;.format(tries))<br>            <br>            if guess &lt; answer:<br>                lower = guess<br>                print(&quot;Too low. \nThe number is now from &quot; + str(lower) + &quot; to &quot; + str(upper) + &quot;\n&quot;)<br>            <br>            elif guess &gt; answer:<br>                upper = guess<br>                print(&quot;Too high. \nThe number is now from &quot; + str(lower) + &quot; to &quot; + str(upper) + &quot;\n&quot;)<br>        <br>        else:<br>            print(&quot;Invalid format. Enter a number.&quot;)<br>            <br>    print(&quot;Would you like to play again?&quot;)<br>    choice = input(&quot;Would you like to play again? y or n&quot;)<br>    <br>    if choice == &quot;y&quot;:<br>        guessingGame()<br>    elif choice == &quot;n&quot;:<br>        print(&quot;Okay. Have a nice day!&quot;)<br>    else:<br>        print(&quot;Invalid option. enter \&#39;y&#39; or \&#39;n&#39;&quot;)<br>        <br>guessingGame()</pre><h3>Other Ideas…</h3><ol><li>Battle Simulation. Choose a battle from a list of heroes and a list of villains. During a battle, random damage is dealt in turns between the hero and the villain. The initial HP (health points) may also be randomly selected, and the weapons (attacks) used may also be randomly chosen.</li><li>Ring in to a Radio Show. The show will ask you a random question. If you answer the question correctly, you can win a random prize!</li><li>“Twenty One”. There are ten card values from 1–10. You are playing against an opponent, taking turns drawing cards from the dealer. The goal is to collect cards which sum to 21, or as close as possible to 21. However, if the sum exceeds 21, your score goes to 0.</li><li>Dice games, e.g. “Mexico” — (<a href="https://funattic.com/dice-games/">https://funattic.com/dice-games/</a>) “The game is played with two dice for rolling. After each game, the lowest dice roll will be considered the losing roll, and as such, that particular player will lose a life. The winner of Mexico is the player left standing after <em>all players have rolled their dice and lost their lives.</em></li></ol><p>etc……..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d297b4c8d07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>