120 likes | 220 Views
CSCI 1001. overview of. computer science. PYTHON I. represent data. manipulate data . construct sequences of operations. collect data. present data. organize and structure data. Boolean:. True, False. Integer:. -1048, 0xA375, 0b1101. Floating point:. 3.14159, 6.02e23.
E N D
CSCI 1001 overview of computer science PYTHON I
represent data manipulatedata construct sequences of operations collect data presentdata organize and structure data
Boolean: True, False Integer: -1048, 0xA375, 0b1101 Floating point: 3.14159, 6.02e23 Strings (of ascii text): “This is a python string” ‘so is this.\t with a tab!’ ‘Just 1 backslash: \\’
assignment: variable = value. age = 30 name = ‘justin’ arithmetic: +, *, -, /, ** lower = age/2 + 7 string manipulation: email = lastname[0:4]+‘0001’ functions: c = math.sqrt(a**2 + b**2)
sequence: in order: age = 30 lower = age/2 + 7 conditional: if age < lower: print “age is less” else: print “age is more”
iterative: while score < 10: print score score = score + 1 for score in range(1,10): print score
for day in range(0,7): if day == 0: print “black” if day == 1 or day == 2: print “heart attack” if day ==3: print “never looking back.” if day == 4: print “I’m in love” if day == 5: print “wait.” if day == 6: print “too late.”
functions: def area(r): return 3.14 * r * r def example(n): for i in range(1,n+1): print i return example(1) example(10)
input: n = raw_input(‘enter a number:’) output: print ‘string’, 7, 3.14, True
lists: [‘a’, ‘b’, ‘c’], [] dictionaries: dict[‘key’] = ‘value’ tuples: (‘a’, ‘b’, ‘c’)
import sys count = 0 for age in sys.stdin: if (int(age) >= 21): count = count + 1 print count n = int(raw_input()) sum = 0 for i in range(1,n+1): sum = sum + i print sum
http://cs1001.us/ Please read Sections 1 and 2 of the Python chapter for Monday