1 / 9

Introduction to Computer Science: Python Programming Basics

This overview covers foundational concepts in computer science with a focus on Python programming. Topics include data structures like dictionaries, string manipulation, and file handling. Learn how to process data, find common elements between lists, and navigate through URLs. This course is designed for beginners and covers practical examples to illustrate programming concepts. Additionally, it touches on error handling and average calculations to give students essential skills for future programming endeavors. Perfect for ages 17 and up!

dinesh
Download Presentation

Introduction to Computer Science: Python Programming Basics

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 V

  2. ages = [20, 18, 17, 26] 17 in ages ages.index(17) sum(ages) range(0,10,2)

  3. ‘abc’ in ‘abcdefg’ ‘how are you’[4:7] s = ‘Mr. Spock’ s[0:2] = ‘Dr’ #Won’t work ‘do re mi faso’.find(‘mi’) for s in ‘i can hazcheez’: print s.upper(),

  4. d = {} # empty dictionary d = {‘nishi’:4, ‘lnp’:1} d[‘nishi’] d[‘neshek’] # KeyError ‘neshek’ in d d[‘neshek’] = 1 len(d)

  5. d = {‘nishi’:4, ‘lnp’:1} d.keys() d.values() d.items() del d[‘lnp’] # in St. Louis dict.fromkeys([1,2,3],’a’)

  6. def common(alice, bob): cs = [] for a in alice: if a in bob: cs.append(a) return cs def common2(as, bs): cs = [] d = dict.fromkeys(bs,True) for a in as: if a in d: cs.append(a) return cs

  7. fileName = raw_input(“file name: ") f = open(fileName) sum = 0 numLines = 0 for currentLine in f: sum = sum + len(currentLine) numLines = numLines + 1 print "Number of lines: ", numLines if numLines != 0: print "Avg length:", sum/numLines

  8. import urllib url = raw_input(“input the url: ") u = urllib.urlopen(url) sum = 0 numLines = 0 for currentLine in u: sum = sum + len(currentLine) numLines = numLines + 1 print "Number of lines: ", numLines if numLines != 0: print "Average line length: ", sum/numLines

  9. http://cs1001.us/ Please read Sections 3.3 and 3.4 for Wednesday

More Related