python基础2---选择结构,循环

2021/9/12 22:06:33

本文主要是介绍python基础2---选择结构,循环,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.结构

# 1
s = 6
if s>60:
    print('及格')
else:
    print('不及格')
print('退出')# 注意缩进

# 2
s = 6
if s>60:
    print('及格')
else:
    print('不及格')
	print('退出')# 注意缩进
#==============================================================
# if else
s = 86
a = 68
if s > 80 and a > 80:
    print('优秀')
else:
    print('不优秀')

s = 86
a = 68
if (80 <= a < 90) or (80 <= s < 90):
    print('良好')
    
#===========================================================
# while
count = 100
while count > 0:
    print('好好学习')
    count -= 1
#=====================================================
# break
count = 100
while count > 0:
    print('好好学习')
    if count == 99:
        break
    count -= 1

# continue
count = 100
while count > 0:
    print('好好学习')
    if count % 2 == 0:
        continue
    count -= 1
#========================================================
# while else
count = 100
while count > 0:
    print('好好学习')
    count -= 1
else:
    print('程序结束')

#===========================================================
# for
name = 'zhangsan'
for i in name:
    print(i)


for i in range(1,20,2):
    print(i,end=' ')
print()

# for(int i=10;i<20;i++)
# for i in range(10,20):

#========================================================

# 随机数
import random
num = random.randint(5,10)
print(num)



这篇关于python基础2---选择结构,循环的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程