SoFunction
Updated on 2024-11-10

python conditional and while loop statements

The Python version is the main one

I. Conditional Statements

  • Basic Structure of Conditional Statements

0 or null is false, the rest is true

if Decision Condition.
Block of statements... Can be multi-line
else:
Block of statements... Can be multi-line

The code is as follows:

day=12

# Multi-conditional statement judgment
if day<7:
print('Activity challenge failed, try again!');
day+=6
elif day>=7 and day <14:
print('Prize 2 for 1, oversized mouse pad/customized fridge sticker');
elif day>=14 and day <21:
print('Prize 3 choices, oversized mouse pad/customized fridge sticker/year of the tiger notebook');
elif day>=21 and day <30:
print(' Prizes 5 choose 3, oversized mouse pad/customized fridge stickers/Year of the Tiger notebook/shoulder bag/WuKong bear dolls');
elif day>30:
print(' Prizes 5 choose 3, oversized mouse pad/customized fridge stickers/Year of the Tiger notebook/shoulder bag/WuKong bear dolls');

The effect is as follows:

#yyds干货盘点#条件语句 - python基础学习系列(12)_运算符

Two.while loop statement

As we all know, the program is generally in order to execute the code, in the code execution process, there will be complex statements, this time the loop statement will play a role

Execute the body of the loop while the condition holds; in python, there is no do while.

while Decision condition.
Block of statements... Can be multi-line

The code is as follows​:

day=0

# while loop statements
while day<30:
day+=7
if day<7:
print('Activity challenge failed, try again!');
elif day>=7 and day <14:
print('Article updated for %s day in a row, prize 2 for 1, oversized mouse pad/customized fridge sticker' % (day));
elif day>=14 and day <21:
print('Article updated for the %sst day in a row, 3 prizes to choose from, oversized mouse pad/customized fridge sticker/year of the tiger notebook' % (day));
elif day>=21 and day <23:
print('Article continuously updated on the %s day, 5 prizes to choose 3, oversized mouse pad/customized fridge sticker/year of the tiger notebook/shoulder backpack/WuKong bear hand puppet' % (day));

The result is as follows.

#yyds干货盘点#while循环语句 - python基础学习系列(13)_while循环

to this article on the python conditional statement and while loop statement is introduced to this article, more related python statement content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!