Page 29 -
P. 29

연습 문제



                              다음은 에이브라함 링컨의 명언이다.
                        연습
                        02
                                명언="""
                                I am for those means which will give the greatest good to the greatest number.
                                Whatever you are, be a good one.
                                Truth is generally the best vindication against slander.
                                You cannot escape the responsibility of tomorrow by evading it today.
                                Always bear in mind that your own resolution to succeed is more important than any one
                                thing.
                                I have always found that mercy bears richer fruits than strict justice.
                                Most people are about as happy as they make up their minds to be.
                                In this sad world of ours, sorrow comes to all.
                                Perfect relief is not possible, except with time.
                                You cannot now realize that you will ever fell better.
                                And yet this is a amistake.
                                You are sure to be happy again.
                                No man is good enough to govern another man without that other's consent.
                                """


                                사용자로부터 검색할 단어를 입력받아 그 검색할 단어가 총 몇 번 나오는지를 카운트하
                              는 프로그램을 작성하려고 한다. 이때 슬라이싱을 통해 일정 범위를 지정하고 이 안에서
                              사용자가 검색하는 단어가 몇 번 카운팅될 수 있도록 코드를 작성해보자.

                              <실행결과 예>

                              I am for those means which will give the greatest good to the great
                              ...중략...

                              검색할 단어 입력:

                              예를 들어 will을 입력했다면 ‘will’이라는 단어가 사용된 횟수 = 2

                              <코드>











                                                                                   8장  데이터의 종류  273
   24   25   26   27   28   29   30