Python Conditional Statements
Main.PythonConditionals History
Show minor edits - Show changes to output
Changed line 32 from:
from random import *
to:
from random import randint
Deleted lines 44-62:
----
(:html:)
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)
Changed lines 31-42 from:
from random import *
answer = randint(0,100)
correct = False
while not(correct):
guess = int(input("Guess a number: "))
if guess < answer:
print("Too low")
elif guess > answer:
print("Too high")
else:
print("Correct!")
correct = True
to:
(:source lang=python:)
from random import *
answer = randint(0,100)
correct = False
while not(correct):
guess = int(input("Guess a number: "))
if guess < answer:
print("Too low")
elif guess > answer:
print("Too high")
else:
print("Correct!")
correct = True
(:sourceend:)
from random import *
answer = randint(0,100)
correct = False
while not(correct):
guess = int(input("Guess a number: "))
if guess < answer:
print("Too low")
elif guess > answer:
print("Too high")
else:
print("Correct!")
correct = True
(:sourceend:)
Changed line 26 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/sooT_DbbCYQ" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/UoXtYnIviEU" frameborder="0" allowfullscreen></iframe>
Changed lines 19-21 from:
and - return TRUE if both statements are TRUE (also &&)
or - return TRUE if either statement is TRUE (also ||)
not - returnthe opposite of the input TRUE/FALSE (also ~)
or - return TRUE if either statement is TRUE (also ||)
not - return
to:
and - return True if both statements are True
or - return True if either statement is True
not - return the opposite of the input True/False
or - return True if either statement is True
not - return the opposite of the input True/False
Changed lines 1-5 from:
(:title MATLAB Conditional Statements:)
(:keywords analysis,MATLAB, Mathworks, greater than, less than, equal to:)
(:description A conditional statement is implementedinto a MATLAB script to change code execution based on the result of logical statements:)
The following tutorial is an introduction toMATLAB conditional statements using the IF command and comparison statements such as those shown below.
(:keywords analysis,
(:description A conditional statement is implemented
The following tutorial is an introduction to
to:
(:title Python Conditional Statements:)
(:keywords analysis, Python, conditional, flow, greater than, less than, equal to:)
(:description A conditional statement is implemented in a Python script to change code execution based on the result of logical statements:)
The following tutorial is an introduction to Python conditional statements using the IF command and comparison statements such as those shown below.
(:keywords analysis, Python, conditional, flow, greater than, less than, equal to:)
(:description A conditional statement is implemented in a Python script to change code execution based on the result of logical statements:)
The following tutorial is an introduction to Python conditional statements using the IF command and comparison statements such as those shown below.
Changed lines 15-16 from:
Certain functions such as AND, OR, XOR, and NOT can be used to combine, select, or reverse the outcome of conditional statements. These logical operations change the results based on input data.
to:
Certain keywords such as AND, OR, and NOT can be used to combine, select, or reverse the outcome of conditional statements. These logical operations change the results based on input data.
Changed lines 22-23 from:
to:
Changed lines 29-44 from:
!!!!Number Guessing Game in MATLAB
clear all
answer = randi(100);
correct = false; % or true
whilenot(correct)
myGuess = input('Guess a number');
if (myGuess==answer)
correct = true;
disp('Correct!')
elseif (myGuess<answer)
disp('Too low, try again')
else
disp('Too high, try again')
end
end
clear all
answer = randi
while
end
to:
!!!!Number Guessing Game in Python
from random import *
answer = randint(0,100)
correct = False
while not(correct):
guess = int(input("Guess a number: "))
if guess < answer:
print("Too low")
elif guess > answer:
print("Too high")
else:
print("Correct!")
correct = True
from random import *
answer = randint(0,100)
correct = False
while not(correct):
guess = int(input("Guess a number: "))
if guess < answer:
print("Too low")
elif guess > answer:
print("Too high")
else:
print("Correct!")
correct = True
Changed line 30 from:
!!!!Number Guessing Game
to:
!!!!Number Guessing Game in MATLAB
Changed lines 30-31 from:
!!!!Source Code
to:
!!!!Number Guessing Game
clear all
answer = randi(100);
correct = false; % or true
while not(correct)
myGuess = input('Guess a number');
if (myGuess==answer)
correct = true;
disp('Correct!')
elseif (myGuess<answer)
disp('Too low, try again')
else
disp('Too high, try again')
end
end
clear all
answer = randi(100);
correct = false; % or true
while not(correct)
myGuess = input('Guess a number');
if (myGuess==answer)
correct = true;
disp('Correct!')
elseif (myGuess<answer)
disp('Too low, try again')
else
disp('Too high, try again')
end
end
Added lines 1-50:
(:title MATLAB Conditional Statements:)
(:keywords analysis, MATLAB, Mathworks, greater than, less than, equal to:)
(:description A conditional statement is implemented into a MATLAB script to change code execution based on the result of logical statements:)
The following tutorial is an introduction to MATLAB conditional statements using the IF command and comparison statements such as those shown below.
'''Operator'''
< - less than
<= - less than or equal to
> - greater than
>= - greater than or equal to
= - equal
~= - not equal to
Certain functions such as AND, OR, XOR, and NOT can be used to combine, select, or reverse the outcome of conditional statements. These logical operations change the results based on input data.
'''Function'''
if - execute code with true logical condition
and - return TRUE if both statements are TRUE (also &&)
or - return TRUE if either statement is TRUE (also ||)
not - return the opposite of the input TRUE/FALSE (also ~)
xor - exclusive OR is TRUE when both inputs differ
The following video tutorial demonstrates logical operations with a number guessing game.
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/sooT_DbbCYQ" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
!!!!Source Code
----
(:html:)
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)
(:keywords analysis, MATLAB, Mathworks, greater than, less than, equal to:)
(:description A conditional statement is implemented into a MATLAB script to change code execution based on the result of logical statements:)
The following tutorial is an introduction to MATLAB conditional statements using the IF command and comparison statements such as those shown below.
'''Operator'''
< - less than
<= - less than or equal to
> - greater than
>= - greater than or equal to
= - equal
~= - not equal to
Certain functions such as AND, OR, XOR, and NOT can be used to combine, select, or reverse the outcome of conditional statements. These logical operations change the results based on input data.
'''Function'''
if - execute code with true logical condition
and - return TRUE if both statements are TRUE (also &&)
or - return TRUE if either statement is TRUE (also ||)
not - return the opposite of the input TRUE/FALSE (also ~)
xor - exclusive OR is TRUE when both inputs differ
The following video tutorial demonstrates logical operations with a number guessing game.
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/sooT_DbbCYQ" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
!!!!Source Code
----
(:html:)
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)