1 / 12

computer science

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.

boyce
Download Presentation

computer science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 1001 overview of computer science PYTHON I

  2. represent data manipulatedata construct sequences of operations collect data presentdata organize and structure data

  3. 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: \\’

  4. 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)

  5. sequence: in order: age = 30 lower = age/2 + 7 conditional: if age < lower: print “age is less” else: print “age is more”

  6. iterative: while score < 10: print score score = score + 1 for score in range(1,10): print score

  7. 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.”

  8. 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)

  9. input: n = raw_input(‘enter a number:’) output: print ‘string’, 7, 3.14, True

  10. lists: [‘a’, ‘b’, ‘c’], [] dictionaries: dict[‘key’] = ‘value’ tuples: (‘a’, ‘b’, ‘c’)

  11. 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

  12. http://cs1001.us/ Please read Sections 1 and 2 of the Python chapter for Monday

More Related