A Flowchart is a diagrammatic representation of an algorithm. It can be helpful for both writing programs and explaining the program to others. A Flowchart is very useful in programming, as it explains a process clearly through symbols and text. Moreover, a flowchart gives you the gist of the process flow in a single glance.
Here we begin to learn the flowchart with if
and
else
in Python
. Copy the following lines into
your script:
# importing "random" for random operations
import random
# Using random() function to generate one random value between 0 and 1
Score = round(random.random()*100)
print(Score)
# Get level
if (Score >= 90):
print("Excellent")
elif (Score >= 60):
print("Pass")
else:
print("Fail")
Selecting all the lines, and then run the script, what is your
result in Console? Here Score
is randomly
generated using random()
function from the
random
library. Type help(random)
for help.
You can play with this script a few times to get different
outputs.
Draw a flow chart based on this script.
Update your script to reflect the following flowchart.
Set a secret integer from 0
to 9
, name
the integer answer
. Make sure your deskmate does not know
the secret number.
Write a function that does the following: if your deskmate is
able to guess your secret number correctly, print You Win!
,
otherwise print You Lose! I Win!
Let your deskmate play the game.
Now it’s your turn to play your deskmate’s game.