上游充通大学 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Elements of Programs Programs are composed of modules. Modules contain statements. Statements contain expressions. Expressions create and process objects. 井 convert.py A program to convert Celsius temps to Fahrenheit by:Suzie Programmer def main(): celsius input("What is the Celsius temperature?" fahrenheit =9.0 5.0 celsius 32 print "The temperature is",fahrenheit,"degrees Fahrenheit." main ( 16
Elements of Programs • Programs are composed of modules. • Modules contain statements. • Statements contain expressions. • Expressions create and process objects. 16 # convert.py # A program to convert Celsius temps to Fahrenheit # by: Suzie Programmer def main(): celsius = input("What is the Celsius temperature? ") fahrenheit = 9.0 / 5.0 * celsius + 32 print "The temperature is", fahrenheit, "degrees Fahrenheit." main()
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Elements of Programs 。Value&Type -A value is one of the fundamental elements -Each value has a type type(object)to check the type >>type('Hello,World!) <type 'str'> >>type(17) <type 'int'> >>>type(1.02) <type 'float'> 17
Elements of Programs • Value & Type – A value is one of the fundamental elements – Each value has a type – type(object) to check the type >>> type('Hello, World!') <type 'str'> >>> type(17) <type 'int'> >>> type(1.02) <type ‘float’> 17