3.1 (Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing the area of a pentagon is , where s is the length of a side. The side can be computed using the formula where r is the length from the center of a pentagon to a ver..
4.14 조건식(Conditional Expressions) - 조건식(Conditional Expressions)이란 조건에 기반한 표현식을 말한다. - 특정한 조건에 제약을 받는 변수를 설정해 그 변수에 값을 넣을 수 있다. * 예시 if x > 0: y = 1 else y = -1 위 예시 코드와 아래의 코드는 같은 의미이다. 아래의 코드가 바로 조건식을 이용해 만든 코드이다. y = -1 if x > 0 else -1 조건식은 완전히 다른 스타일의 문법형태이다. * 조건식 형태 expression1 if boolean-expression else expression2 - expression1 은 boolean-experession 이 참(True)일 경우의 결과 값이며, 거짓(False)의 경우 ..
4.11 논리연산자(Logical Operators) - 논리연산자(Logical Operators) or, and 그리고 not은 복합적인 조건식을 만들때 사용한다. - 우리는 두 개 이상의 조건식을 작성하여야 하는 경우가 생긴다. - 이런 경우 논리연산자를 이용하여 두 개 이상의 조건식을 조합하여 표현할 수 있다. - 논리연산자(Logical Operators)는 부울 연산자(Boolean Operators)라고도 알려져 있다. - 종류는 not, and, or 이 있다. * not 논리 연산자 p not p Example (assume age = 24, gender = 'F') True False not (age > 18) 은 거짓(False) 이다, 왜냐면 (age > 18) 가 참(True) 이..
4.7 중첩 if 문과 다중 if-elif-else 문(Nested if and Multi-Way if-elif-else Statements) - if 문 안에다가 또 다른 if 문을 선언하여 중첩 if 문을 만들 수 있다. - 중첩 if 문의 횟수 제한은 없다. if i > k: if j > k: print("i and j are greater than k") else: print("i is less than or equal to k") - 중첩 if 문은 다양한 대안을 구현하는 데 사용 할 수 있다. - 예를 들어, 점수에 따라 학점을 변수에 다르게 할당하는 프로그램을 짤 경우 이용을 할 수 있다. * 학점 프로그램 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19..
명품 자바 에센셜 Chapter 4 실습문제. *진도 순서에 맞는 문법으로만 코딩한 것이며, 아직 나오지 않은 문법은 배제하고 풀이하였습니다. 1.아래 실행 결과와 같이 출력하는 다음 main()을 가진 Song 클래스를 작성하라. Song 클래스는 노래 제목 title 필드, 생성자, getTitle() 메소드로 구성된다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public class Song { private String songname; public Song(String songname){ this.songname = songname; } private String getTitle(){ return songname; } public static void ma..
4.4 if 문(if Statements) - if 문(if Statements)은 조건식이 참(true)일 경우 명령을 실행하는 명령문이다. - 조건식이 거짓(false)일 경우, if문 블록(block)안에 있는 명령문은 건너뛰고 다음 코드를 해석한다. - if문은 단일, 2 중, 다중, if-else if-else 형식으로 다양하게 만들 수 있다. *단일 if문 작성형태 if boolean-expression: statement(s) # statements(s) 앞에 반드시 공백이 있어야 한다. - statement(s)를 입력할 때, 반드시 if 키워드(keyword) 옆에 최소 하나의 공백이 있어야 한다. - 각각의 다른 명령(statements)들도 동일한 칸 수의 공백을 이용하여야 한다. *..
선택문(selection statements) - 조건에 따라 실행할 명령이 결정되는 명령을 선택문이라고 한다. - 다른 언어와 마찬가지로 파이썬도 선택문(selection statemets)을 제공한다. - 선택문(selection statemets)을 통해 두 개 이상의 선택지를 만들어 결정 할 수 있다. - 선택문(selection statemets)은 부울 표현식(Boolean expressions)로 되어있는 조건(conditions)을 이용한다. * 선택문 예제 1 2 3 4 5 6 7 8 9 import math radius = eval(input("Enter the radius: ")) if radius = 0 true == = 같다 radius == 0 false != ㅁ 같지 않다 ra..
2.1 (Convert Celsius to Fahrenheit) Write a program that reads a Celsius degree from the console and converts it to Fahrenheit and displays the result. The formula for the conversion is as follows: fahrenheit = (9 / 5) * celsius + 32 1 2 3 4 5 6 celsius = eval(input("Enter a degree in Celsius: ")) fahrenheit = (9/5) * celsius + 32 print(celsius, " celsius is ", fahrenheit,"Fahrenheit.") Colored ..
- Total
- Today
- Yesterday
- 파이썬 선택문
- 버츄어박스
- 백준
- 파이썬 진수 변환
- 자바스크립트 그래프
- 파이썬 if문
- 자바 에센셜 실습문제
- 자바스크립트 자료구조
- 백준 11501
- 파이썬 리스트
- 자료구조
- 웹
- css
- 파이썬 예제
- 명품 c++ 실습
- 파이썬 함수
- 파이썬 객체
- 자바
- 파이썬 연산자
- 파이썬 for
- 파이썬 터틀
- 파이썬 문자열
- 파이썬 while
- 파이썬
- 파이썬 클래스
- 백준 10451
- css 박스
- 백준 1874
- 파이썬 단계적 개선
- css 그리드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |