python条件判断和循环语句实例(二)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

###条件语句 if elif else###
num = 3
flg=True
if num == 3 and flg:            # 判断num的值
    print('boss')
elif num == 2:
    print( 'user')
elif num == 1:
    print ('worker')
elif num < 0:           # 值小于零时输出
    print ('error')
else:
    print( 'roadman')     # 条件均不成立时输出
###条件语句 if elif else###

###循环语句###
#在Python中,提供while,foreach循环,没有do..while循环
#循环控制语句:break,continue,pass(pass是空语句,是为了保持程序结构的完整性)
#while 循环
count = 0
while (count < 9):
    print('The count is:', count)
    count = count + 1
print("Good bye!")

#foreach 循环
str='Python' # 第一个实例
for letter in str:
    print('当前字母 :', letter)

fruits = ['banana', 'apple', 'mango'] # 第二个实例
for fruit in fruits:
    print ('当前水果 :', fruit)
print("Good bye!")
###循环语句###

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值