
점프 투 파이썬의 예제를 푼 뒤, 그것에 대해 정리한 포스팅
새 창을 통해 점프 투 파이썬 으로 이동
# 1.
a = 80
b = 75
c = 55
print((a+b+c)/3)
# 1.result
70.0
# 2.
def avg(*args):
sum = 0
for score in args:
sum += score
average = sum / len(args)
print(f"You took {len(args)} exam(s) and average is {average}.")
avg(80, 75, 55)
avg(80, 75, 55, 100)
# 2.result
You took 3 exam(s) and average is 70.0.
You took 4 exam(s) and average is 77.5.
# 0.
def avg(*args):
sum = 0
for score in args:
sum += score
average = sum / len(args)
if average >= 80:
print(f"You took {len(args)} exam(s) and average is {average}. Awesome!")
elif 60 <= average < 80:
print(f"You took {len(args)} exam(s) and average is {average}.")
else:
print(f"You took {len(args)} exam(s) and average is {average}. You can do better next time!")
avg(80, 75, 55)
avg(80, 75, 90, 100)
avg(80, 75, 30, 45)
# 0.result
You took 3 exam(s) and average is 70.0.
You took 4 exam(s) and average is 86.25. Awesome!
You took 4 exam(s) and average is 57.5. You can do better next time!
# 1.
print(13%2)
# 1.result
1
# 2.
def finder(num):
if num%2 == 0:
print(f"{num} is even number")
else:
print(f"{num} is odd number")
finder(13)
finder(10)
# 2.result
13 is odd number
10 is even number
# 1.
hong = "8811201068234"
print(hong[:7])
print(hong[6:])
# 1.result
8811201
1068234
# 2.
def slice(num):
if type(num) == str:
a = num.replace("-", "")
birth = a[:7]
other = a[6:]
print(f"Birthday : {birth}, Unique number : {other}")
else:
print("Please enter your social number in quotation marks")
slice("881120-1068234")
slice("8811201068234")
slice(881120-1068234)
# 2.result
Birthday : 8811201, Unique number : 1068234
Birthday : 8811201, Unique number : 1068234
Please enter your social number in quotation marks
# 1.
pin = "881120-1068234"
print(pin[7])
# 1.result
1
# 2.
def gender(num):
if type(num) == str:
a = num.replace("-", "")
gender = a[6]
if gender == "1" or gender == "3":
print("Your gender is male")
elif gender == "2" or gender == "4":
print("Your gender is female")
else:
print("Please recheck your social number")
else:
print("Please enter your social number in quotation marks")
gender("881120-1068234")
gender("8811202068234")
gender("881120-8068234")
gender(881120-1068234)
# 2.result
Your gender is male
Your gender is female
Please recheck your social number
Please enter your social number in quotation marks
# 1.
a = "a:b:c:d"
b = a.replace(":", "#")
print(b)
# 1.result
a#b#c#d
# 1.
list = [1, 3, 5, 4, 2]
list.sort()
list.reverse()
print(list)
# 1.result
[5, 4, 3, 2, 1]
# 2.
list = [1, 3, 5, 4, 2]
a = sorted(list)
a.reverse()
print(a)
# 2.result
[5, 4, 3, 2, 1]