car = 'subaru'
print("Is car == 'subaru'? I predict True.")
if car == 'subaru':
print(car == 'subaru')
#5-2 更多的条件测试
略
alien_color = ['green']
if 'green' in alien_color:
print('恭喜你获得了5个点')
print('版本2')
alien_color = ['red']
if 'green' in alien_color:
print('恭喜你获得了5个点')
alien_color = ['green']
if 'green' in alien_color:
print('恭喜你获得了5个点')
else:
print('恭喜你获得10个点')
print('版本2')
alien_color = ['red']
if 'green' in alien_color:
print('恭喜你获得了5个点')
else:
print('恭喜你获得10个点')
alien_color = ['green']
if 'green' in alien_color:
print('恭喜你获得了5个点')
elif 'yellow' in alien_color:
print('恭喜你获得10个点')
else:
print('恭喜你获得15个点')
print('版本2')
alien_color = ['red']
if 'green' in alien_color:
print('恭喜你获得了5个点')
elif 'yellow' in alien_color:
print('恭喜你获得10个点')
else:
print('恭喜你获得15个点')
print('版本3')
alien_color = ['yellow']
if 'green' in alien_color:
print('恭喜你获得了5个点')
elif 'yellow' in alien_color:
print('恭喜你获得10个点')
else:
print('恭喜你获得15个点')
age = 10
if age < 2:
print("婴儿")
elif age < 4:
print('蹒跚学步')
elif age < 13:
print('儿童')
elif age < 20:
print('青少年')
elif age < 65:
print('成年人')
else:
print('老年人')
#5-7 喜欢的水果
略
names = ['ergou','tiezhu','shitou','admin','erya']
for name in names:
if name == 'admin':
print('Hello ' + name + ',would you like to see a status report?')
else:
print('Hello ' + name +',thank you for logging in again')
names = []
if names:
for name in names:
if name == 'admin':
print('Hello ' + name + ',would you like to see a status report?')
else:
print('Hello ' + name +',thank you for logging in again')
else:
print('We need to find some users!')
current_users = ['ergou','tiezhu','Shitou','admin','erya']
new_users = ['Ergou','xiaofeng','shitou','shuanzi','dongzi']
linshi = []
for name in current_users:
linshi.append(name.lower())
for name in new_users:
if name.lower() in linshi:
print(name + '已被使用,请输入别的用户名!')
else:
print('该用户名未被使用!')
numbers = list(range(1,10))
print (numbers)
for number in numbers:
if number == 1:
print(str(number)+'st')
elif number == 2:
print(str(number)+'nd')
elif number == 3:
print(str(number)+'rd')
else:
print(str(number)+'th')