점프 투 파이썬의 예제를 푼 뒤, 그것에 대해 정리한 포스팅
새 창을 통해 점프 투 파이썬 으로 이동
# 1.
def is_odd(num):
if int(num) % 2 == 0:
print(f"{num} is even number")
else:
print(f"{num} is odd number")
is_odd(1)
is_odd(387)
# 1.result
1 is odd number
387 is odd number
# 1.
def avg(*args):
sum = 0
for num in args:
sum += int(num)
average = sum / len(args)
print(f"The average is {average}.")
avg(4, 8, 12)
avg(4, "8", 12)
# 1.result
The average is 8.0.
The average is 8.0.
# 1.
input1 = input("Enter the first number:")
input2 = input("Enter the second number:")
total = int(input1) + int(input2)
print("The sum of the two numbers is %s" % total)
# 1. result
Enter the first number:3
Enter the second number:6
The sum of the two numbers is 9
# 1.
a1 = open("test.txt", 'w')
a1.write("Life is too short")
a1.close()
a2 = open("test.txt", 'r')
print(a2.read())
a2.close()
# 1.result
Life is too short
# 1.
user_input = input("Enter the content to be saved:")
a = open("test.txt", 'a')
a.write(user_input)
a.write("\n")
a.close()
# 1.result
(in "test.txt")
Hello everyone
welcome to the python world
# 1.
a = open("test.txt", 'r')
content = a.read()
a.close()
content = content.replace("java", "python")
a = open("test.txt", 'w')
a.write(content)
a.close()
# 1.result
(in "test.txt")
Life is too short
you need python