#!/bin/env
cars = ['aodi','benchi','changan','Diao']
for car in cars:
if car == 'changan':
print (car.upper())
else:
print (car.title())
print ("判断两个值是否相等会考虑大小写")
for car in cars:
if car == 'Diao':
print (car.lower())
else:
print (car.title())
#!/bin/env
list=['qingjiao','rousi','dasuan']
for cai in list:
print ("adding " + cai.title() + ".")
print ('青椒肉丝 has finished')
print ('现在,青椒肉丝的肉木有了,我们需要告诉顾客青椒肉丝为啥没肉')
list=['qingjiao','rousi','dasuan']
for cai in list:
if cai == 'rousi':
print ('rousi mei le')
else:
print ("adding " + cai.title() + ".")
print ('青椒肉丝 has finished')
list = []
if list:
for cai in list:
print ('adding ' + "cai")
print ("Finished making your qingjiaorous")
else:
print ('Are you want a qingjiaorousi')
#!/bin/env
message = 'hello,world'if message != 'this is a big problem':
print ('every thing will be OK!')
age = 34print (age)
if age <= 30:
print ('not enough,please try again')
else:
print ('the day you went away')
if && else
#!/bin/env
age = 32print ('根据年龄判断收费情况,像数字这种用if判断时第一条不匹配会继续向下走')
if age < 4:
print ('welcome,free')
elif age < 18:
print ('welcome,price = 8 $')
elif age < 65:
print ('welcome,price = 16 $')
else:
print ('welcome,price = 4 $')
print ('if语句并不一定非要有else,也可以用 age > 65结尾,不用else')
print ('但是当参数不是数字类型时,必须要注意返回结果为True还是False,比如加菜,如果全程都用if判断,每个菜都会被判断,如果点了就输出一条信息')
print ('如果没点就会跳过,不会影响下面的判断,都是独立的运行')
list = ['naiyou','jiandan']
if'naiyou'inlist:
print ('adding naiyou')
if'huashengjiang'inlist:
print ('adding huashengjiang')
if'jiandan'inlist:
print ('adding jiandan')
print ('下面开始使用if-elif-else结构,报错后会跳过后面的判断')
list = ['python','java','C+']
if'python'inlist:
print ('get python')
elif'wowo'inlist:
print ('get wowo')
elif'java'inlist:
print ('get java')
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# BY:wenchao.Li time: 2021/5/18
# Python break 语句
# Python break语句,就像在C语言中,打破了最小封闭for或while循环。
# break语句用来终止循环语句,即循环条件没有False条件或者序列还没被完全递归完,也会停止执行循环语句。
# break语句用在while和for循环中。
# 如果您使用嵌套循环,break语句将停止执行最深层的循环,并开始执行下一行代码。
# Python语言 break 语句语法:
for letter in'Python': # 第一个实例
if letter == 'h':
break
print ('当前字母 :', letter)
var = 10 # 第二个实例
whilevar > 0:
print ('当前变量值 :', var)
var = var -1ifvar == 5: # 当变量 var 等于 5 时退出循环
break
print ("Good bye!")
#!/usr/bin/env python# -*- coding:utf-8 -*-# BY:wenchao.Li time: 2021/4/20print ('break,中断后面的程序')
for i inrange (3):
print (i+1)
username=input ("please input your name:")
password=input ("please input your password:")
if username=='liwenchao'and password=='123456':
print ("Welcome {} back" .format(username))
breakelse:
print ("user or pass error")
if i > 3:
breakprint ("your name has locked")
#!/usr/bin/env python# -*- coding:utf-8 -*-# BY:wenchao.Li time: 2021/5/10# break 是跳出循环# continue是跳出本次循环,这个脚本有问题# 游戏:# 1.欢迎进入**游戏# 2,输入用户名。默认没有游戏币# 3.提示用户买游戏币(100块钱30个币,必须是100的倍数,重置不成功,可以提示再次重置)# 4.玩一局游戏扣2个币,猜大小,两个筛子想加>6就是大,使用随机数模拟筛子# 5.只要猜对了,会奖励一个币。可以继续玩(问你玩不玩,或者没钱了)import random
print ("*" *50)
print ("welcome to aomen")
name=input("please input your name: ")
money=0
answer=input ("please input y/n:")
if answer == 'y':
while money <= 2:
n=int(input("please in money:"))
if n%100 == 0and n >0:
money=(n//100)*30print ("your money is {} now" .format(money))
print ("login.........")
whileTrue:
t1=random.randint(1,6)
t2=random.randint(1,6)
total =t1 + t2
guess=input("please input big/small:")
print (t1,t2,total)
if (total > 6and guess == 'big') or (total < 6and guess == 'small'):
print("you are success")
money -= 1print("your money is {} now".format(money))
else:
print("you are failed")
money -= 2print("your money is {} now".format(money))
answer = input("are you continue? y/n")
if (answer == 'n') or (money < 2):
#breakpass
continue
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# BY:wenchao.Li time: 2021/5/18
# Python continue 语句
# Python continue 语句跳出本次循环,而break跳出整个循环。
# continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。
# continue语句用在while和for循环中。
# Python 语言 continue 语句语法格式如下:
for letter in'Python': # 第一个实例
if letter == 'h':
continue
print ('当前字母 :', letter)
var = 10 # 第二个实例
whilevar > 0:
var = var -1ifvar == 5:
continue
print ('当前变量值 :', var)
print ("Good bye!")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!