if False:print('I can do it')print('believe me')print('believe yourself')"""
the data the input function has received is 'str' type,
so we should transform its type
"""
age =int(input('please input your age:'))if age >=18:print(f'your age is {age},and you can pass')else:print(f"your age is {age},and you can't pass")print('system close')
二、elif语句
age =int(input('please input your age :'))if age <18:print(f'your age is {age}, juveniles')elif(age >=18)and(age <=60):print(f'your age is {age}, adult')
elif 60< age <=80: # the 6 row and 9 row are equivalent
print(f'your age is {age}, retiree')
elif age >80:print(f'your age is {age}, high age')
三、if嵌套语句
money =int(input('coins please :'))if money !=0:print('please get on')
seat =int(input('how many seats are available :'))if seat !=0:print('you could get available seats')else:print('there is not free seat')else:print('sorry, please get off')
四、else语句1
i =0while i <5:print('媳妇儿, 我错了')
i +=1else:print('太好了, 媳妇儿原谅我了')print('__________________')
i =0while i <5:if i ==2:print('这一遍不真诚,别道歉了')breakprint('媳妇儿, 我错了')
i +=1else:print('太好了, 媳妇儿原谅我了')print('__________________')
i =0while i <5:if i ==2:print('这一遍不真诚,算了,继续吧')
i +=1continueprint('媳妇儿, 我错了')
i +=1else:print('太好了, 媳妇儿原谅我了')
五、else语句2
str1 ='python'
str2 =''for i in str2:print(i)else:print('循环正常结束')print('-------------')for i in str1:print(i)if i =='n':break#print(i)else:print('循环正常结束')print('-------------')for i in str1:if i =='t':continueprint(i)else:print('循环正常结束')
六、if-else语句举例1
"""
猜拳游戏
"""
import random # import module
per =int(input('please show (1--石头; 2--剪刀; 3--布): '))
cer = random.randint(0,2) # the computer values are random numbers
if(per ==1 and cer ==2)or(per ==2 and cer ==3)or(per ==3 and cer ==1):print('player win')
elif per == cer:print('tie')else:print('player lose')
文章目录一、if语句二、elif语句三、if嵌套语句四、else语句1五、else语句2六、if-else语句举例1七、if-else语句举例2一、if语句if False: print('I can do it') print('believe me')print('believe yourself')"""the data the input function has received is 'str' type,so we should transform its ty