阅读更多
#1-20的列表
a=list(range(1,21))
print(a)
#1-10000的列表
squares=[]
for value in range(1,10001):
square=value
squares.append(square)
print(squares)
#1-10000的列表,核实从1开始10000结束,求1-10000之和
a=list(range(1,10001))
print(a)
print(min(a))
print(max(a))
print(sum(a))
#1-20的奇数列表
bs=[value for value in range(1,21,2)]
print(bs)
#1-10立方列表
bs=[value**3 for value in range(1,11)]
print(bs)
#测试你的预测结果是否与实际结果相同
print('\n')
car='bmw'
if car=='bmw':
print("Is car=='bmw'?I predict True.")
else:
print("\n Is car=='audi'?I predict False.")
print(car)
#检查是否相等 (有大小写不同的处理方法)
car="Bmw"
if car.lower()=="bmw":
print(True)
else:
print(False)
#测试特定值是否在列表内(有大小写不同的处理方法)
cars=['audi','Bmw','subaru','toyota']
car='bmw'
cars=car.lower()
if car not in cars:
print(True)
else:
print(False)
#设置age的值,利用if—elif-else结构判断处于人生哪个阶段
age=19
if age<2:
print("baby")
elif age<4:
print('toddle')
elif age<13:
print('children')
elif age<20:
print('tenager')
elif age<65:
print('adult')
else:
print('the elderly')
age=19
if age<2:
a=("baby")
elif age<4:
a=('toddle')
elif age<13:
a=('children')
elif age<20:
a=('teenager')
elif age<65:
a=('adult')
else:
a=('the elderly')
print("I am a "+a)
#检测列表是否为空 若为空,该怎么样,不为空有怎么样
users=['admin','nike','elic','lihua','hanhan']
if users:
for user in users:
if user=='admin':
print("Hllo"+user+" ,would you like to see a status report?")
else:
print('Hllo'+user+',thank you for logging in again.')
else:
print('We need to find some users')
#在用for循环和if语句时一定要注意缩进##
#检查用户名是否重复
current_users=['admin','nike','elic','lihua','hanhan']
new_users=['dsaf','nike','clear','pepper','delicious']
for new_user in new_users: #在对比两个列表的时候注意 for循环只针对一个列表 从第一个元素到最后一个元素
if new_user in current_users:
print('Sorry,the username already exists!')
else:
print('Congratulations on using the username successfully!')
figures=[1,2,3,4,5,6,7,8,9]
for figure in figures:
if figure==1:
print(str(figure)+'st')
elif figure==2:
print(str(figure)+'nd')
elif figure==3:
print(str(figure)+'rd')
else:
print(str(figure)+'th')