Pusan National University power PNU Python Spring 2019

  • Slides: 25
Download presentation
Pusan National University power PNU 세계로 미래로 Python 언어의 구조 Spring, 2019 School of

Pusan National University power PNU 세계로 미래로 Python 언어의 구조 Spring, 2019 School of CSE Pusan National University http: //lstudio. egloos. com/2238441

세계로 미래로 power PNU Python의 입력문 input 함수 정수나 소수점수를 읽음 x = input()

세계로 미래로 power PNU Python의 입력문 input 함수 정수나 소수점수를 읽음 x = input() print x * 2 input 함수의 인수로 프롬프트(prompt: 안내문구)를 줄 수 있음 x = input("Enter an integer: ") raw_input 함수 문자열을 읽음 raw_input 사용 예 name = raw_input("Your name? ") print "Hello, %s? " % name Advanced Broadcasting & Communications Lab. 6

세계로 미래로 power PNU 함수 사용 예 별을 10개 출력하는 프로그램 def star 10():

세계로 미래로 power PNU 함수 사용 예 별을 10개 출력하는 프로그램 def star 10(): a = 10 while (a > 0): print "*", a=a-1 print star 10() 위와 같이 함수를 사용하면 while 루프를 두 번 사용할 필요가 없음 Advanced Broadcasting & Communications Lab. 19

세계로 미래로 power PNU 별을 헤는 밤 별을 n개 출력하는 프로그램 def star(a): while

세계로 미래로 power PNU 별을 헤는 밤 별을 n개 출력하는 프로그램 def star(a): while (a > 0): print "*", a=a-1 print star(8) star(9) star(10) 인수 a에 따라 출력되는 별 개수가 달라짐 Advanced Broadcasting & Communications Lab. 21

세계로 미래로 power PNU 모듈 정의와 사용법 모듈의 정의와 사용법 star. py def star(a):

세계로 미래로 power PNU 모듈 정의와 사용법 모듈의 정의와 사용법 star. py def star(a): while (a > 0): print "*", a=a-1 print def main(): star(10) if __name__ == '__main__': main() Advanced Broadcasting & Communications Lab. sandwitch. py import star def main(): a = 10 while (a > 0): star(a) a=a-1 if __name__ == '__main__': main() 23