알파카징징이 알파카징징이 코딩하는 알파카

데이터 구조 및 분석 ch_1_2 Hello World in Python

» writing

KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다

ch_1_2 Hello World in Python

정의


Hello World in Python

1. Hello World in Python
- procedure-oriented program => function
(<-> object-oriented program => class)
def main() :
    print "hello, world"
    print "This program computes the average of two exam"

    score1, score2 = input("Enter the scores : ")
    average = (score1 + score2 ) / 2

    print "The average of the scores is : ", average

main()

# hello, world
# This program computes the average of two exam
# Enter the scores : 89 78
# The average of the scores is :  83.5
2. Hello World in Python
- object-oriented program => class
class HelloWorld :
    def __init__(self) :
        print("Helllo world! just one more time! ")
    def __del__(self) :
        print("Good bye!")
    def performAverage(self, val1, val2) :
        average = (val1 + val2) /2.0
        print("The average of the scores is : ", average)

def main() :
    world = HelloWorld()
    score1, score2 = map(int, input("Enter the scores : ").split())
    world.performAverage(score1, score2)
main()

# Helllo world! just one more time! 
# Enter the scores : 89 67
# The average of the scores is :  78.0
# Good bye!