Skip to content

Commit

Permalink
Deploying to gh-pages from @ 4fdc7e7 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Mar 28, 2024
1 parent 1c2acdb commit ae38c69
Show file tree
Hide file tree
Showing 11 changed files with 1,495 additions and 4 deletions.
239 changes: 239 additions & 0 deletions 2024/pyladies-en-vienna-2024-spring/beginners-en/and-or/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@

<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>

Beginners course PyLadies Vienna: Or &amp; and

</title>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">



<link rel="stylesheet" href="/static/css/naucse.css">
<link rel="stylesheet" href="/static/css/body.css">
<link rel="stylesheet" href="/static/css/pygments-lovelace-style.css">
<link rel="stylesheet" href="/static/css/ipython.css">


<link rel="canonical" href="https://naucse.python.cz/lessons/beginners-en/and-or/" />


<style>



</style>
</head>

<body>
<nav class="header">
<ul class="container menu">
<li><a href="/" class="logo"><h1>PyLadies Vienna</h1></a></li>
<li><a href="/sponsorship/" class="menu-link"><h2>Support Us</h2></a></li>
<li><a href="/mentorship/" class="menu-link"><h2>Mentorship</h2></a></li>
<li><a href="/runs/" class="menu-link"><h2>Courses</h2></a></li>
</ul>
</nav>



<div class="page">
<div class="container">





<div class="lesson-content">



<h1><em>Or</em> &amp; <em>and</em></h1>
<p>In addition to the operators that we saw in the Comparison lesson, we will now add 3 more logical (Boolean) operators to the table:</p>
<table class="table">
<tr>
<th>Symbol</th>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td><code>and</code></td>
<td><code>x and y</code></td>
<td>True if both operands are true</td>
</tr>
<tr>
<td><code>or</code></td>
<td><code>x or y</code></td>
<td>True if either operand is true</td>
</tr>
<tr>
<td><code>not</code></td>
<td><code>not x</code></td>
<td>True if the operand is false<br>
(it negates the operand)</td>
</tr>
</table><div class="highlight"><pre><span></span><span class="c1"># This program gives naive life advice.</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">'Answer "yes" or "no".'</span><span class="p">)</span>
<span class="n">happy_status</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">'Are you happy?'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">happy_status</span> <span class="o">==</span> <span class="s1">'yes'</span><span class="p">:</span>
<span class="n">happy</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">elif</span> <span class="n">happy_status</span> <span class="o">==</span> <span class="s1">'no'</span><span class="p">:</span>
<span class="n">happy</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'I do not understand!'</span><span class="p">)</span>

<span class="n">rich_status</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">'Are you rich?'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rich_status</span> <span class="o">==</span> <span class="s1">'yes'</span><span class="p">:</span>
<span class="n">rich</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">elif</span> <span class="n">rich_status</span> <span class="o">==</span> <span class="s1">'no'</span><span class="p">:</span>
<span class="n">rich</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'I do not understand!'</span><span class="p">)</span>

<span class="k">if</span> <span class="n">rich</span> <span class="ow">and</span> <span class="n">happy</span><span class="p">:</span>
<span class="c1"># rich and at the same time.</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'Congratulations!'</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">rich</span><span class="p">:</span>
<span class="c1"># rich but not "rich and happy",</span>
<span class="c1">#so must be only rich.</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'Try to smile more.'</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">happy</span><span class="p">:</span>
<span class="c1"># must be only happy.</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'Try to spend less.'</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># neither happy nor rich.</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"I'm sorry for you."</span><span class="p">)</span>
</pre></div><div class="admonition note"><p>What happens if you answer something other than "Yes" or "No"?</p>
<p>The variables <code>happy</code> and <code>rich</code> won't be set, and later when they are needed, the program will end with an error.</p>
<p>We will learn how to handle errors <a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/exceptions/">next time</a>.</p>
</div>


</div>





<div class="row prev-next">



<div class="col text-left">
<a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/comparisons/">← <span class="d-none d-sm-inline">Comparison</span></a>
</div>




<div class="col text-left">
<a href="/2024/pyladies-en-vienna-2024-spring/sessions/loops/">↑ <span class="d-none d-sm-inline">Lesson: Conditions, modules and functions</span></a>
</div>




<div class="col text-right">
<a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/functions/"><span class="d-none d-sm-inline">Functions</span> →</a>
</div>



</div>




</div>
</div>



<script type="text/javascript" src="/static/js/solutions.js"></script>

<div class="footer container">
<hr>
<div class="lesson-attribution">


<p>Translated by Alexandru Dumitru</p>

<p>Originally written by Petr Viktorin, 2014-2017 for <a href="https://naucse.python.cz/course/pyladies/beginners/and-or/">PyLadies CZ</a>.</p>



<p>
Licence:
<a href="https://creativecommons.org/licenses/by-sa/4.0/">
Creative Commons Attribution-ShareAlike 4.0 International
</a>
</p>



</div>
</div>
<footer>
<div class="container">
<div class="global-pyladies">
© 2024 PyLadies Vienna. All rights reserved.
<br>
<a href="/agb/">Impressum, AGB</a>
<br>
We are a part of <a href="https://pyladies.com">international PyLadies</a>.
</div>
<ul>
<li>
<a href="https://discord.gg/v2qdvbD2dn" target="_blank">
<img src="/static/img/discord-logo.png">
</a>
</li>
<li>
<a href="mailto:[email protected]" >
<img src="/static/img/mail-white.png">
</a>
</li>
<li>
<a href="https://twitter.com/pyladies_vie" target="_blank">
<img src="/static/img/twitter-white.png">
</a>
</li>
<li>
<a href="https://www.instagram.com/pyladies_vienna" target="_blank">
<img src="/static/img/instagram-logo.png">
</a>
</li>
<li>
<a href="https://github.com/UndeadFairy/pyladies_vienna" target="_blank">
<img src="/static/img/github-white.png">
</a>
</li>
<li>
<a href="https://www.meetup.com/PyLadies-Vienna/" target="_blank">
<img src="/static/img/meetup.png">
</a>
</li>
<li data-toggle="tooltip" title="Linkedin">
<a href="https://www.linkedin.com/company/pyladies-vienna" target="_blank">
<img src="/static/img/linkedin-logo.png">
</a>
</li>
</ul>
</div>
<div class="clear"></div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>



</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ <h3>Solution</h3>


<div class="col text-right">
<a href="/2024/pyladies-en-vienna-2024-spring/sessions/loops/back/"><span class="d-none d-sm-inline">End of lesson</span> →</a>
<a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/and-or/"><span class="d-none d-sm-inline">Or &amp; and</span> →</a>
</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h1>Comparison – Solution [0]</h1>


<div class="col text-right">
<a href="/2024/pyladies-en-vienna-2024-spring/sessions/loops/back/"><span class="d-none d-sm-inline">End of lesson</span> →</a>
<a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/and-or/"><span class="d-none d-sm-inline">Or &amp; and</span> →</a>
</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h1>Comparison – Solution [1]</h1>


<div class="col text-right">
<a href="/2024/pyladies-en-vienna-2024-spring/sessions/loops/back/"><span class="d-none d-sm-inline">End of lesson</span> →</a>
<a href="/2024/pyladies-en-vienna-2024-spring/beginners-en/and-or/"><span class="d-none d-sm-inline">Or &amp; and</span> →</a>
</div>


Expand Down
Loading

0 comments on commit ae38c69

Please sign in to comment.