# HCI574 - lecture 2 - 2015 print 1 + 4 # print outputs the result of the code right to the word print #print 3 * 2 # means: interpreter, ignore anything to the right of # in the same line print 3 / 1.8 # / means divide (dividing by a whole number is strange - more about that later ...) print 2 ** 8 # ** is the "power of" operation print 3 * "spam" # do you think this should work? print 3 > 2 # evaluate the truth of this statement -> returns True or False print 2 * 3 # fix this! # Variable assignment example (much more on variables later!) n = 4 # puts/writes (assigns) the value 4 to the variable n, uses a single =, not == or <- # if you do n = 4 in the interactive python shell, it will print n's value # but: the same line inside a Python script (.py) will need a print in front to print n's value n = 2 + n # adds 2 to n's value and re-assigns the results to n (overwrite) print n # Group coding 1 # calculate (and print out) 12 degrees of Fahrenheit as Celcius (32 F = 0 C, 1.8 F = 1 C) #print ??? # put in math to convert 12 Fahrenheit to Celcius C = (12-32)*5/9 print C # Group coding 2: F -> C conversion as above but now use variables F = 12 C = (F-32)*5/9 # your math from above but use F instead of 12 print F, "Degrees Fahrenheit = ", C, "Degrees Celcius" # Interactive version - will ask the user for F F = float(raw_input("Enter Degrees Fahrenheit: ")) C = (F-32)*5/9 # same as above print F, "Degrees Fahrenheit = ", C, "Degrees Celcius"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question