점프 투 파이썬의 예제를 푼 뒤, 그것에 대해 정리한 포스팅
새 창을 통해 점프 투 파이썬 으로 이동
# 1.
i = 0
nums = []
while i < 1000:
if i % 3 == 0:
nums.append(i)
i += 1
else:
i += 1
result = 0
for num in nums:
result += num
print(result)
# 1.result
166833
# 1.tring to be clean
i = 0
result = 0
while i < 1000:
if i % 3 == 0:
result += i
i += 1
else:
i += 1
print(result)
# 2.
def cal(num):
i = 0
result = 0
while i < 1000:
if i % int(num) == 0:
result += i
i += 1
else:
i += 1
print(f"The sum of multiplies of {num} less than 1000 is {result}!")
cal(3)
cal("5")
# 2.result
The sum of multiplies of 3 less than 1000 is 166833!
The sum of multiplies of 5 less than 1000 is 99500!
# 1.
i = 1
while i < 6:
print("*"*i)
i += 1
# 1.result
*
**
***
****
*****
# 1.
for i in range(1, 101):
print(i)
# 1.result
1
2
3
...
100
# 1.
scores = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
result = 0
for i in scores:
result += i
avg = result / len(scores)
print(avg)
# 1.result
79.0
# 2.
scores = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
def avg(group):
sum = 0
for score in group:
sum += score
result = sum / len(group)
print(f"Your class average is {result}.")
avg(scores)
# 2.result
Your class average is 79.0.
# 1.
numbers = [1, 2, 3, 4, 5]
result = [n*2 for n in numbers if n%2==1]
print(result)
# 1.result
[2, 6, 10]