Bullet Modders
Become a member of our community

Go down
Posts : 2
Reputation : 1
Join date : 2019-05-02

Python Programming Part 2: Condition and Loop Empty Python Programming Part 2: Condition and Loop

on Thu May 02, 2019 8:35 am
Condition is used anywhere. For example if today is a rainy day, we will not go outside. That is a condition, but that is not 'specific'. Computer can only work with specific things. As a programmer you will have to transfer all of the condition in a way that a computer can understand. For example a rainy day, what is considered a rainy day? Does its temperature gets lower, does the ground gets more wet and slippery? If so, how much? Well that is a hard one, let's start with a simpler condition. Assuming we want to say if a day is the end of January, then we want to say 'Hello upcoming February'. In python it would look like this:


current_day = read_date(); // this function is for demonstration purpose only
current_month = read_month(); // assuming you get those 2 values from somewhere.
if current_day == 31 and current_month == 1:
    print("Hello upcoming February")

You as a programmer , have to translate the condition 'at the end of January' to something really 'specific'. So at the end of Janary => last day of January. And in January there are 31 days. So the last day of January must be 31. January is the first month of the year so we use the value 1 as a way of saying that this is January. Remember that in this case the value is 1.

So a value can contain anything. As a tool programmer we do not know what the value stands for so we will have to test it in game using trial and errors method, just changing it to see if it affects anything.
Here is the structure of Python condition:

if condition:

if conditon:

if condition:
else if another_condition:

if condition:
if another_condition:

A condition must end with a ':' , the code on the condition must be 'indented'. A good way of indenting in python is to press Space 4 times.
The first one is pretty straight forward, if the condition is True, then execute the code do_something_1, otherwise SKIP it.
The second one contains an 'else' clause, if the condition is True, then execute the code do_something_2, otherwise execute the code do_otherthing_2.
I will leave the rest to you to explain it. Using those 2 explanations I just post. Remember that you will have to say what is the difference between the third one and the last one.
You can use the keyword 'and' and 'or' like I did to check for more complex condition.
Big Evil
Big Evil
Posts : 17
Reputation : 0
Join date : 2019-05-01
Age : 21
Location : Paraná,Brazil

Python Programming Part 2: Condition and Loop Empty Re: Python Programming Part 2: Condition and Loop

on Thu May 02, 2019 8:53 am
very good to see you showing your knowledge here, I hope you all enjoy it
Back to top
Permissions in this forum:
You cannot reply to topics in this forum