01. 연습문제의 첫 줄에는 100과 200의 합을 출력하기 위한 방법을 보여주고 있다. print() 함수와 + 연산을 이용하여 200, 300, 400의 합을 결과와 같이 화면에 출력해보자. 이때 print() 함수 내부에 들어갈 알맞은 값을 적어라.

print( 100, '+', 200, '=', 300 )

print(200, '+', 300, '+', 400, '=', 900)
02. 밑줄 친 부분에 알맞은 대입문을 사용하여 width 변수에는 30, height 변수에는 60 값이 출력 되도록 하라.

width = 30
height = 60
03. 위의 코드에서 width와 height 변수를 두개의 줄에 걸쳐 선언하지 말고 한 줄에 할당하는 동시 할당문을 사용하여 width 변수에는 30, height 변수에는 60 값이 출력되도록 하라.

width, height = 30, 60
04. width와 height라는 변수에 각각 40,20 값을 할당한 후 이 두 변수를 이용하여 곱셈 연산자를 적용한 후 다음과 같이 삼각형의 면적(area)을 구하는 프로그램을 작성하라.

1) 이 프로그램을 get_triangle_area.py 이름의 코드로 작성한 후 수행시켜라.
2) 이 프로그램을 대화창에서 작성하여 수행시켜라.
3) width와 height 변수를 동시 할당문으로 40, 20을 할당하는 프로그램을 작성하라.
width, height = 40, 20
tri = width * height / 2
print("삼각형의 면적 :",tri)
05. 정사각형의 면적을 구하기 위하여 사용자로부터 밑변의 길이를 정수로 입력받아서 다음과 같이 출력하라

w = int (input ("정사각형의 밑변을 입력하시오 : "))
print("정사각형의 면적 :", 40 * 40)
06. print() 함수와 + 연산을 9개 사용하여 1에서 10까지 정수의 합을 다음과 같이 출력해보자.

print("1에서 10까지의 합 :",1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10)
07. print() 함수와 * 연산을 9개 사용하여 10!을 다음과 같이 출력해보자.

print("10! = ", 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10)
08. 섭씨온도를 화씨온도로 변환하는 식은 다음과 같다.
fahrenheit = (9/5) * celsius + 32
이 식을 바탕으로 섭씨온도를 0도에서 50도까지 10도 단위로 증가시키면서 이에 해당하는 화씨온도를 다음과 같이 출력하는 프로그램 cel2fah.py를 작성하라.

print("섭씨 화씨")
celsius = 0
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
celsius += 10
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
celsius += 10
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
celsius += 10
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
celsius += 10
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
celsius += 10
fahrenheit = (9/5) * celsius + 32
print(celsius," ", fahrenheit)
print("섭씨 화씨")
for celsius in range (0,51, 10):
fahrenheit = (9/5) * celsius + 32
print("%-3d %5.1f"%(celsius, fahrenheit))
09. 앞서 다룬 섭씨온도를 화씨온도로 변환하는 식을 바탕으로 사용자로부터 섭씨온도를 입력받아서 다음과 같이 화씨온도로 출력하라

celsius = int(input("섭씨온도를 입력하세요 : "))
fahrenheit = (9/5) * celsius + 32
print("섭씨",celsius,"도는 화씨",fahrenheit, "도 입니다.")
10. 사용자로부터 반지름 값을 입력받아서, 이 반지름을 가진 원의 둘레와 면적을 다음과같이 출력하라. 이 값을 구하기 위하여 PI = 3.141592라는 변수를 사용하라.

PI = 3.141592
radius = int(input("원의 반지름을 입력하세요 : "))
print("원의 둘레 =", PI * 2 * radius, end = ", ")
print("원의 면적 =", radius ** 2 * PI)
11. print() 함수를 사용하여 다음과 같은 내용을 출력하라

print("It's really hot!")
print("I said \"Hello!\" to him")
print('He said "What\'s there?"')
print("Newline character is \\n, Tab character is \t.")
print("Working directory is C:\\workspace\\mywork.")
string = """It's really hot!
I said "Hello!" to him.
He said "What's there?"
Newline character is \\n, Tab character is \\t.
Working direcotry is C:\\workspace\\mywork."""
print(string)
'Python' 카테고리의 다른 글
[따라하며 배우는 파이썬과 데이터과학] 2장 주관식 문제 (0) | 2025.03.02 |
---|---|
[따라하며 배우는 파이썬과 데이터과학] 1장 심화문제 (0) | 2025.03.02 |
[따라하며 배우는 파이썬과 데이터과학] 1장 주관식 문제 (0) | 2025.03.02 |
[Python | 웹크롤링, api] 날씨 데이터를 활용한 옷차림 가이드 (0) | 2025.02.24 |