問題:如何利用for循環(huán)夷狰,輸出以下結(jié)果:
1 + 1 = 2
2 + 1 = 3
.
.
10 + 1 = 11
for num in range(1, 11):
print(str(num) + ' + 1 =', num + 1)
for 和if 嵌套
songslist = ['Holy Diver', 'Thunderstruck', 'Rebel Rebel']
for song in songslist:
if song == 'Holy Diver':
print(song, ' - Dio')
elif song == 'Thunderstruck':
print(song, ' - AC/DC')
elif song == 'Rebel Rebel':
print(song, ' - David Bowie')
for 嵌套循環(huán)
for i in range(1, 10):
for j in range(1, 10):
print('{} X {} = {}'.format(i, j, i * j))