[점프 투 파이썬] 04장 연습 문제 풀이

2021. 4. 18. 15:02·Python & SQL/Python Problems

점프 투 파이썬 04장 연습 문제

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Q1
def is_odd(number):
    if number % 2 == 0:
        return False
    else:
        return True
 
print(is_odd(3))  # True
print(is_odd(4))  # False
 
# 또는
 
is_odd = lambda x: False if x % 2 == 0 else True
 
print(is_odd(3))
print(is_odd(4))
 
# Q2
def average(*args):
    total = 0
    for i in args:
        total += i
    return total / len(args) 
 
print(average(1, 2, 3, 4, 5))
 
# Q3 오류 수정하기
input1 = input("첫번째 숫자를 입력하세요:")
input2 = input("두번째 숫자를 입력하세요:")
 
total = input1 + input2
print("두 수의 합은 %s 입니다" % total)
 
# 수정 후
input1 = input("첫번째 숫자를 입력하세요:")
input2 = input("두번째 숫자를 입력하세요:")
 
total = int(input1) + int(input2)
print("두 수의 합은 %s 입니다" % total)
 
# Q4
''' 출력결과가 다른 하나는? 3번
1. print("you" "need" "python")
2. print("you"+"need"+"python")
3. print("you", "need", "python")
4. print("".join(["you", "need", "python"]))
'''
 
# Q5 결괏값 바로잡기
f1 = open('test.txt', 'w')
f1.write('Life is too short')
 
f2 = open("test.txt", 'r')
print(f2.read())
 
# 수정 후
f1 = open('test.txt', 'w')
f1.write('Life is too short')
f1.close()  # 열린 파일 객체를 닫아주어야 한다.
 
f2 = open('test.txt', 'r')
print(f2.read())
f2.close()
 
# Q6
user_input = input("저장할 내용을 입력하세요: ")
f = open('test.txt', 'a', encoding = 'utf-8') # 'a' : 내용 추가, encoding : 한글깨짐 방지
f.write(user_input)
f.write('\n') # 입력 내용 구분을 위한 줄 바꿈 추가
f.close()
 
# Q7
f = open('test.txt', 'r')
a = f.read()
f.close()
 
a = a.replace('java', 'python')
 
f = open('test.txt', 'w')
f.write(a)
f.close()
Colored by Color Scripter
cs

'Python & SQL > Python Problems' 카테고리의 다른 글

[프로젝트 오일러/파이썬] Multiples of 3 and 5  (0) 2021.04.18
[점프 투 파이썬] 05장 연습 문제 풀이  (0) 2021.04.18
[점프 투 파이썬] 03장 연습 문제 풀이  (0) 2021.04.18
[점프 투 파이썬] 02장 연습 문제 풀이  (0) 2021.04.16
[초보 300제] 파이썬 파일 입출력과 예외 처리(291~300) 풀이  (0) 2021.04.12
'Python & SQL/Python Problems' 카테고리의 다른 글
  • [프로젝트 오일러/파이썬] Multiples of 3 and 5
  • [점프 투 파이썬] 05장 연습 문제 풀이
  • [점프 투 파이썬] 03장 연습 문제 풀이
  • [점프 투 파이썬] 02장 연습 문제 풀이
J. Son
J. Son
Petit à petit l'oiseau fait son nid.
  • J. Son
    Steady Study Log
    J. Son
  • 전체
    오늘
    어제
    • 분류 전체보기 (170) N
      • Python & SQL (63)
        • Python Basics (21)
        • Python Problems (23)
        • Python Practice (11)
        • MySQL (1)
        • Git & GitHub (7)
      • ML & DL (7) N
      • Projects (5)
        • Project Portfolio (5)
      • AI Camp (4)
        • Camp Reflection (4)
      • Concept Notes (6)
        • Statistics & Stata (4)
        • Mathematics (2)
      • Archive (84)
        • Java (24)
        • R (1)
        • Languages (49)
        • Miscellaneous (10)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

    • GitHub
    • WikiDocs
  • 공지사항

  • 인기 글

  • 태그

    Python
    어린왕자 불어
    파이썬
    객체
    MySQL
    초보자를 위한 파이썬 300제
    python streamlit
    프로젝트 오일러
    점프투파이썬 연습문제
    불어 공부
    Stata
    파이썬 문제
    머신러닝
    파이썬 크롤링
    자바
    streamlit
    machine learning
    불어 관계대명사
    복합과거
    python problem
    share.streamlit.io
    맥 git
    passe compose
    점프투파이썬 연습문제 풀이
    Github
    프랑스어 공부
    어린왕자 프랑스어
    Le Petit Prince
    GIT
    파이썬 streamlit
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
J. Son
[점프 투 파이썬] 04장 연습 문제 풀이
상단으로

티스토리툴바