python条件判断语句

python yekong 987℃

输入操作

password = input('请输入密码')
print('您刚刚输入的密码是:', password)

判断输入类型

a = input('请输入')
print(type(a))

强制类型转换 字符串转数字

a = int('123')

条件判断

if True:
    print('True')
else:
    print('False')
    
if 0:
    print('True')
else:
    print('False')
score = 77
if score >= 90:
    print('本次考试等级为A')
else:
    print('考试不合格')

elif和and的使用

score = 87
if score >= 90 and score <= 100:
    print('本次考试等级为A')
elif score >= 80 and score < 90:
    print('本次考试等级为B')
else:
    print('本次考试等级为E')

引入外部库 输出随机数

import random
x = random.randint(0, 100)
print(x)
喜欢 (0)