Python 第五章

源码:

#5-3
print('5-3\n')
alien_color = 'green'
if alien_color == 'green':
	print('You have just earned 5 points!')
else:
	print('')
print('\n') 

alien_color = 'red'
if alien_color == 'green':
	print('You have just earned 5 points!')
else:
	print('')
print('\n') 
 
	
#5-4
print('5-4\n')
alien_color = 'green'
if alien_color == 'green':
	print('You have just earned 5 points!')
else:
	print('You have just earned 10 points!')	
print('\n')
	
alien_color = 'red'
if alien_color == 'green':
	print('You have just earned 5 points!')
else:
	print('You have just earned 10 points!')
print('\n') 
	
#5-5
print('5-5\n')
alien_color = 'green'
if alien_color == 'green':
	print('You have just earned 5 points!')
elif alien_color == 'yellow':
	print('You have just earned 10 points!')
elif alien_color == 'red':
	print('You have just earned 15 points!')
print('\n')
	
alien_color = 'yellow'
if alien_color == 'green':
	print('You have just earned 5 points!')
elif alien_color == 'yellow':
	print('You have just earned 10 points!')
elif alien_color == 'red':
	print('You have just earned 15 points!')	
print('\n')
	
alien_color = 'red'
if alien_color == 'green':
	print('You have just earned 5 points!')
elif alien_color == 'yellow':
	print('You have just earned 10 points!')
elif alien_color == 'red':
	print('You have just earned 15 points!')
print('\n') 
 
	
#5-8
print('5-8\n')
lists = ['admin', 'Peter', 'Davin', 'Rain', 'Red']
for list in lists:
	if list == 'admin':
		print('Hello admin, would you like to see a status report?', end = ' ')
	else:
		print('Hello ' + list + ', thank you for logging in again.', end = ' ')
	print('\n') 

输出结果:

5-3

You have just earned 5 points!





5-4

You have just earned 5 points!


You have just earned 10 points!


5-5

You have just earned 5 points!


You have just earned 10 points!


You have just earned 15 points!


5-8

Hello admin, would you like to see a status report?

Hello Peter, thank you for logging in again.

Hello Davin, thank you for logging in again.

Hello Rain, thank you for logging in again.

Hello Red, thank you for logging in again.


你可能感兴趣的:(Python 第五章)