男の子の教育Python 9期の第1課の練習問題の解答
956 ワード
1、whileサイクルを使用して1 2 3 4 5 8 10を入力する
2、1-100のすべての数の和を求めます
3、出力1-100内のすべての奇数
4、出力1-100内のすべての偶数
5、1-2+3-4+5を求めます...99のすべての数の和
6、ユーザー登録(三回再試行)
i = 0
while i < 10:
i += 1
if i == 7:
continue
else:
print(i)
2、1-100のすべての数の和を求めます
i = 0
sum = 0
while i < 100 :
i += 1
sum = sum + i
print(sum)
3、出力1-100内のすべての奇数
i = 0
while i < 100:
i += 1
if i%2 == 1:
print(i)
else:
continue
4、出力1-100内のすべての偶数
i = 0
while i < 100:
i += 1
if i%2 == 0:
print(i)
else:
continue
5、1-2+3-4+5を求めます...99のすべての数の和
i = 1
sum = 0
while i < 100 :
if i%2 == 1 :
sum += i
else:
sum -= i
i += 1
print(sum)
6、ユーザー登録(三回再試行)
i = 0
while i < 3 :
username = input(' :')
password = input(' :')
i += 1
if username == 'oldboy' and password == '123':
print(' , !')
break
else:
print(' , ')
continue