avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1018

Abstract

ort</span> random</pre></div><div id="c878"><pre><span class="hljs-attr">X</span> = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">9</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,] <span class="hljs-comment"># X gets</span> <span class="hljs-attr">Y</span> = X <span class="hljs-comment"># Y gets</span></pre></div><div id="3d83"><pre><span class="hljs-attr">sample_X</span> = random.sample (X,<span class="hljs-number">1</span>) <span class="hljs-comment">#sample_X gets</span> <span class="hljs-attr">sample_Y</span> = random.sample (Y,<span class="hljs-number">1</span>) <span class="hljs-comment">#sample_Y gets</span></pre></div><div id="b63e"><pre><span class="hljs-attr">X</span> = sample_X.pop() <span class="hljs-comment"># X gets</span> <span class="hljs-attr">Y</span> = sample_Y.pop()

Options

<span class="hljs-comment"># Y gets</span></pre></div><div id="0313"><pre><span class="hljs-keyword">print</span> (X,<span class="hljs-string">"+"</span>,Y) answer = <span class="hljs-keyword">int</span> (<span class="hljs-keyword">input</span> (<span class="hljs-string">"what is the answer? "</span>)) <span class="hljs-meta"># answer gets</span></pre></div><div id="3e41"><pre>if answer == (<span class="hljs-keyword">X</span>+<span class="hljs-keyword">Y</span>):# answer equals print (<span class="hljs-string">"yes,"</span>,(<span class="hljs-keyword">X</span>+<span class="hljs-keyword">Y</span>),<span class="hljs-string">"is correct."</span>) else: print (<span class="hljs-string">"sorry,the answer is "</span>,(<span class="hljs-keyword">X</span>+<span class="hljs-keyword">Y</span>))</pre></div><p id="040f">Jim McAulay🍁 writes 75 word stories and adds some humour to every story he writes.</p><p id="72bd">The boss told me to have a good day.</p><p id="7aa0">So I went home.</p></article></body>

75 word story

The Problem With Equals In Python

And have a good day

Photo by Remy Gieling on Unsplash

In Python, equals can be difficult for beginners.

Equals (==) means is equal to. It can be either True or False.

2+2 == 4 will return True.

2+2 == 5 will return False.

Equals (=) means the value of this object is equal to that. This is assigned to that.

four = 4

four = (96 – 4 )/6

Use equals to mean is equal to. (==)

Use gets to mean is assigned to (=)

import random
X = [1,2,3,4,5,6,9,8,9,] # X gets
Y = X # Y gets
sample_X = random.sample (X,1) #sample_X gets
sample_Y = random.sample (Y,1) #sample_Y gets
X = sample_X.pop() # X gets
Y = sample_Y.pop() # Y gets
print (X,"+",Y)
answer = int (input ("what is the answer? ")) # answer gets
if answer == (X+Y):# answer equals
    print ("yes,",(X+Y),"is correct.") 
else:
    print ("sorry,the answer is ",(X+Y))

Jim McAulay🍁 writes 75 word stories and adds some humour to every story he writes.

The boss told me to have a good day.

So I went home.

Python
Python For Beginners
Jim Mcaulay
Illumination
Humor
Recommended from ReadMedium