小编Kat*_*ugh的帖子

在python中使用多个不相互排斥的Ifs

a=0
while a<30:
    a+=1
    print(a)
    if a%3==0:
        print("This is a multiple of 3.")
    if a%5==0:
        print("This is a multiple of 5.")
    else:
        print("This is not a multiple of 3 or 5.")
Run Code Online (Sandbox Code Playgroud)

我希望这个else语句只在前面的if语句中的NEITHER为真时打印.我不想使用if,elif,else因为变量可能是3和5的倍数.

python if-statement

4
推荐指数
1
解决办法
317
查看次数

标签 统计

if-statement ×1

python ×1