python的选择语句是什么语句

藏色散人
Libérer: 2020-07-07 11:34:40
original
8792 人浏览过

python的选择语句主要有三种形式,分别是:1、if语句;2、“if...else”语句;3、“if...elif...else”多分支语句。

python的选择语句是什么语句

Python 选择语句

Python中选择语句主要有三种形式,分别为:

if语句
    格式:
        if 表达式:
            语句块(执行代码)
Copier après la connexion
if...else语句
    格式:
        if 表达式:
            语句块
        else:
            语句块
Copier après la connexion
 if...elif...else多分支语句
    格式:
        if 表达式1:
            语句块1
        elif 表达式2:
            语句块2
        elif 表达式3:
            语句块3
        ...
        else:
            语句块n
Copier après la connexion
# if 实例
print("今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问几何?")
num = int(input("请输入你认为符合条件的数字:"))
if (num % 3 == 2) and (num % 5 == 3) and (num % 7 == 2):
    print(num,"符合三三数之剩二,五五数之剩三,七七数之剩二")
# if...else 实例
print("今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问几何?")
num = int(input("请输入你认为符合条件的数字:"))
if (num % 3 == 2) and (num % 5 == 3) and (num % 7 == 2):
    print(num,"符合三三数之剩二,五五数之剩三,七七数之剩二")
else:
    print(num,"不符合!")
Copier après la connexion

推荐:《python教程

以上是python的选择语句是什么语句的详细内容。更多信息请关注PHP中文网其他相关文章!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!