Learn Python 012: for loop
阿新 • • 發佈:2017-07-16
super iou list orm ice clas and let mat
# 1 vowels = 0 consonants = 0 for letter in ‘supercalifragilisticexpialidocious‘: if letter.lower() in ‘aeiou‘: vowels = vowels + 1 elif letter == ‘ ‘: pass else: consonants = consonants + 1 print(‘There are {} vowels in the text.‘.format(vowels)) print(‘And there are {} consonants in the text.‘.format(consonants)) # 2 students = { ‘male‘: [‘Bob‘, ‘Clark‘, ‘Frank‘, ‘Graig‘], ‘female‘: [‘Alice‘, ‘Emma‘, ‘Helen‘] } for key in students.keys(): for name in students[key]: if ‘a‘ in name: print(name)
Learn Python 012: for loop