Velofel ZA For example you can call the seal method
Velofel
ZA For
example you can call the seal method to get the sealing of a number. So if you
pass 2.9 here and then print the result we should see 3. Let me delete all this
other code here. Alright, let's run this program there you go. So we get 3.
Another useful method is the floor method, so let's give that a try, floor of
2. 9. What do you think we're going to get? We get 2. Now there are so many
functions built in this module and we don't really have time to go through all
of them. But let me show you how we can learn about them on your own. Open up
your browser and search for Python 3 math module. Make sure to add the version
python 3. Because the math module in python 2 is slightly different from the
math module in python 3. So python 3 math module, now here you can see the
documentation of this kind of module let's go let's have a look, if you scroll
down, we can see the list of all the functions and their explanation. So as an
exercise I encourage you to have a quick look at this documentation. See what
functions are there for you in case you need them. In this tutorial, I'm going
to talk to you about if statements in Python if statements are extremely
important in programming and they allow us to build programs that can make
decisions based on some condition. So if some conditions are true we're going
to do certain things, otherwise we're going to do other things. Here's an
example. Over here I've got this text file with a bunch of rules for our
program. If it's a hot day, perhaps we want
Velofel
South Africa (ZA) to
tell the user it's a hot day, so make sure to drink plenty of water. Otherwise,
if it's cold, so here's another condition if this condition is true we're going
to tell the user it's a cold day so where warm clothes. And otherwise if it's
either hot or cold, we want to tell the user it's a lovely day. So let me show
you how to write a program that simulates these rules. So, back to our program
here, we start by defining a boolean variable is underline hot. We set this to
true. Next, we add an if statement, so if, here we need to add a condition, in
this case we're going to use our boolean variable. So, is underline hot. So if
this values to true. Then we're going to do certain things. In this case, we
want to tell the user hey it's a hot day, drink plenty of water. So, back to
our program after our condition we add a colon, now, note that when I press
enter pycharm automatically indents our cursor. Now any code that we write here
will be executed if this condition is true, otherwise it will be ignored. Here
is an example. Let's write a print statement, here I'm going to use double
quotes because I want to use an apostrophe in our string. So, it's a hot day.
Now let's press enter you can see the cursor is still indented, that means we
can write more code that we executed if this condition is true, in this case
let's say we don't want to write any extra code, so to terminate this block we
need to press shift and tab, now the cursor is at the beginning of the line so
lets write a print statement with a message like enjoy your
Velofel South
Africa .
Now when we run this program, because this condition is true, you're doing to
say this message followed by this second message, take a look, so run, there
you go, it's a hot day enjoy your day. But if I go over here and change this
boolean value to false and run the program again, our first message disappears
and we only see the second message, enjoy your day. So this is how if
statements work. Now back here we can add another print statement let's say
drink plenty of water. Now because this spirant statement is also indented it
will be executed if this condition is true. So I'm going to revert is hot to
true and run the program one more time. There you go, so it's a hot day, drink
plenty of water, and enjoy your day. Alright now let's add a second rule here,
if it's hot we're going to execute these two lines, otherwise if it's not hot
we want to print a different message. So here we are moving an indentation and
typing els colon. Now when we press enter once again our cursor indented so the
code that we write here will be executed if this condition is not true. So here
we can print it's a cold day, print, where warm clothes. Now let's run our
program one more time. So we get the message about a hot day followed by enjoy
your day. You don't see any message about a cold day. Now if we go back here on
the top. And change this boolean value to false and run our program we see
different set of messages. It's a cold day wear warm clothes and enjoy your
day. But there's a problem with our program
Comments
Post a Comment