1. 程式人生 > >記錄python學習之路------------------------《python程式設計從入門到實踐》作業合集

記錄python學習之路------------------------《python程式設計從入門到實踐》作業合集

每天只更新學習的內容,今天就更新作業吧。做個勤奮的樓主


4-1因為我沒有寫pizza,選擇的自己喜歡的顏色。

#-*-coding:GBK-*-
#-*-coding:utf-8-*-
#4-1
colors=['orange','blue','red','black']
for color in colors:
	print(color)
	print("i like "+color+"\n")
print("我真的很喜歡很多顏色,橘色是我偶像的應援色,藍色是藍家的應援色,紅色是仙后的顏色,黑色就是酷酷的,我就是最愛橘色")
#4-2
print('----------------4-2------------------')
animals=['dog','cat','bird','sheep','wugui']
for animal in animals:
	print(animal)
	print("a "+animal+" would like to pet")
print("any of these animals would be pet")

#-*-coding:GBK-*-
#-*-coding:utf-8-*-
#4-3
for value in range(1,21):
  print(value)
#4-4 4-5
print('----------------------------------')
numbers=list(range(1,1000001))
print(numbers)
print(min(numbers))
print(max(numbers))
print(sum(numbers))
#4-6
print('----------------------------------')
digit=list(range(1,20,2))
for num in digit:
	print(num)
#4-7
print('----------------------------------')
a=list(range(3,31,3))
print(a)
for b in a:
	print(b)
#4-8
print('----------------------------------')
aa=[]
for bb in range(1,11):
	aaa=bb**3
	aa.append(aaa)
print(aa)
#4-9 列表解析
print('----------------------------------')
hh=[dd**3 for dd in range(1,11)]
print(hh)

#-*-coding:GBK-*-
#-*-coding:utf-8-*-
#4-10
hh=[dd**3 for dd in range(1,11)]
print(hh)
print("the first therr items in the list are:")
print(hh[:3])
print("three items from the middle of the list are:")
print(hh[4:7])
print("the last three items in the list are:")
print(hh[-3:])
#4-11
print('---------------------------------')
my_colors=['orange','blue','red','black']
friend_colors=my_colors[:]
print(my_colors)
print(friend_colors)
my_colors.append('pink')
friend_colors.append('purple')
print("my friend color:")
for aa in friend_colors:
	print(aa)
print("my color")
for bb in my_colors:
	print(bb+"\n")
#4-13
print('---------------------------------')
foods=('chaofan','xiangcai','yuecai','chaomian','tang')
for food in foods:
	print(food)
foods=('dangchaofan','xiangcai','chuangcai','chaomian','tang')
for food in foods:
	print(food)

#-*-coding:GBK-*-
#-*-coding:utf-8-*-
#5-1
a=22
print('a==22?我猜是true')
print(a==22)
print('a>=18?我猜是true')
print(a>18)
print('a!=38?我猜是true')
print(a!=38)
print('a<=20?我猜是false')
print(a<=20)
my_love='shinhwa'
print('my love are superjunor?我猜false')
print(my_love=='superjunor')
print('my love are SHIMHWA? 我猜false')
print(my_love=='SHINHWA')
print('my love are shinhwa?我猜是true')
print(my_love=='shinhwa')
print('my love are not hot?我猜是true')
print(my_love!='hot')
print('my love are SHINHWA?我猜是ture')
print(my_love.upper()=='SHINHWA')
print('my love are Shinhwa?我猜是false')
print(my_love=='Shinhwa')
#5-2
print('------------------------------------')
num1=22
num2=39
print(num1==22 and num2==39)
print(num1==21 and num2==39)
print(num1==22 or num2==34)
ha=['eric','m','kdw','zpj','junjin','andy']
if 'eric' in ha:
 print("in here")
if 'shinhwa' not in ha:
 print("not here")
 #5-3外星人的顏色
 print('------------------------------------')
alien_color=['green','yellow','red']
alien1_color='green'

if alien1_color=='green':
 print("\nyou win 5 points")

#5-4 顏色2
print('------------------------------------')
alien2_color='green'
if alien2_color=='green':
 print("\nyou win 5 points")
else:
 print("you win 10 points")
alien3_color='red'
if alien3_color=='green':
 print("\nyou win 5 points")
else:
 print("\nyou win 10 points")
#5-5 
print('------------------------------------')
alien4_color='green'
if alien4_color=='green':
 print("\nyou win 5 points")
elif alien4_color=='yellow':
  print("\nyou win 10 points")
elif alien4_color=='red': 
 print("you win 15 points")
 
alien4_color='yellow'
if alien4_color=='green':
 print("\nyou win 5 points")
elif alien4_color=='yellow':
  print("\nyou win 10 points")
elif alien4_color=='red': 
 print("you win 15 points")
 
alien4_color='red'
if alien4_color=='green':
 print("\nyou win 5 points")
elif alien4_color=='yellow':
  print("\nyou win 10 points")
elif alien4_color=='red': 
 print("you win 15 points")

#5-6
print('------------------------------------')
age=22
if age<2 :
 print("他是一個嬰兒")
elif age<4 :
 print("他正在蹣跚學步")
elif age<13:
 print("他是個兒童")
elif age<20:
 print("他是個青少年")
elif age<65:
 print("他是個成年人")
else:
 print('他是個老人')

#5-7
print('------------------------------------')
favorite_fruits=['apple','plum','grape','orange']
if 'apple' in favorite_fruits:
 print("\nyou really like apple")
if 'plum' in favorite_fruits:
 print("you really like plum")
if 'grape' in favorite_fruits:
 print("you really like grape")
if 'orange' in favorite_fruits:
 print("you really like orange")
if 'plum' and 'orange' in favorite_fruits:
 print("you really like plum and orange")

#5-8
print('------------------------------------')
users=['eric','susan','admin','junjin','andy','judy']
for user in users:
  if user=='admin':
     print("\nhello "+user.title()+",would you like to see a status report?")
  else:
      print("\nhello "+user.title()+",thank  you for logging in again")

#5-9
print('------------------------------------')
users=['eric','susan','admin','junjin','andy','judy']
if users:
 for user in users:
  if user=='admin':
     print("\nhello "+user.title()+",would you like to see a status report?")
  else:
     print("\nhello "+user.title()+",thank  you for logging in again")
else:
 print("\nwe need to find some users!")

#5-10
print('------------------------------------')
current_users=['eric','susan','admin','junjin','andy','judy']
new_users=['ERIC','sue','admin','tom','jerry','penny']
for new_user in new_users:
 if new_user.lower() in current_users:
    print("\nthis name exist!you should input new name")
 else:
   print(new_user+"未被使用")
#5-11
print('------------------------------------')
digits=list(range(1,10))
for digit in digits:
 print(digit)
for digit in digits:
 if digit<2:
  print(str(digit)+"st"+"\n")
 elif digit<3:
  print(str(digit)+"nd"+"\n")
 elif digit<4:
  print(str(digit)+"rd"+"\n")
 else:
  print(str(digit)+"th"+"\n")

一口氣更新了兩章的習題,好吧,排版我實在承受不來。只能做個不精緻的豬豬女孩。