[关闭]
@CLSChen 2019-02-26T09:40:09.000000Z 字数 666 阅读 707

小陈同学的Python学习笔记

Python

beersong.py

可以输出从99到0的一长串儿歌

  1. word = "bottles"
  2. for beer_num in range (99,0,-1):
  3. print(beer_num,word,"of beer on the wall.")
  4. print(beer_num,word,"of beer.")
  5. print("Take one down")
  6. print("Pass it around")
  7. if beer_num == 1:
  8. print("No more bottles of beer on the wall.")
  9. else:
  10. new_num = beer_num -1
  11. if new_num == 1:
  12. word = "bottle"
  13. print(new_num, word, "of beer on the wall.")
  14. print()

vearch.py

定义了两个函数,第二个函数是第一个函数的升级版,可以用来取两个对象的交集。

  1. def search4vowels(phrase:str)->set:
  2. """Display any vowels found in an asked-for word."""
  3. vowels = set('aeiou')
  4. return vowels.intersection(set(phrase))
  5. def search4letters(phrase:str,letters:str)->set:
  6. """Return a set of the 'letters' found in 'phrase.取交集"""
  7. return set(letters).intersection(set(phrase))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注