Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
> 2*2
4
> 2/1
2
> Meet Me
SyntaxError: invalid character in identifier
> Meet Me
SyntaxError: i
Type: floating point 3.2
Complex 5+4j
Integer 3
10/3=3.33333333333
10/3=3
10%3=1(remainder)
4*2=14
_
1. > python prompt
2. + The concatenation operator.
3. Variable: A named reference to a data object.
4. Comment: #, it is useful to programmers because th
# Name: Haishan Yuan
# Unsername: haishan_yuan
# Section: 2
# Assignment: CS8,Project 1
# part 1
# drawPolygon: makes myTurtle draw a regular polygon with numSides sides
#
and side length given by sideLength parameter.
import turtle
myTurtle=turtle.Turtle
Homework 5: CS8, Introduction to Computer Science
Due at the beginning of class on Monday, July 27, 2015
Name: _Haishan Yuan_(apply late day)_
UCSBNetID: _haishan_yuan_
Lab section: _Tues. 11-12:20_
Download the scores.txt file from the Monday, July 20 le
# Haishan Yuan
import turtle
myTurtle=turtle.Turtle()
def drawTriangleSide100(myTurtle):
for i in range(3):
myTurtle.forward(100)
myTurtle.left(120)
return
def drawTriangle(myTurtle,sideLength):
for i in range(3):
myTurtle.forward(sideLength)
myTurtle.lef
# Haishan Yuan
# section2_functions_lab5
# nameLengths: takes two parameters, a list nameList and a string firstLetters.
#
finds all the names in nameList that start with any of the letters
#
in firstLetters, and then prints them and their length out
#
in
# Haishan Yuan
# haishan_yuan
# section(2) Tues. 11:00-12:20
# reverse: this function takes one string parameter,s
#
and returns the reverse of s.
def reverse(s):
rev="
for i in range(len(s)-1,-1,-1):
rev+=s[i]
return rev
# breakString: this function take
# Name:Haishan Yuan
# NetID:haishan_yuan
# Section2_functions_lab2
# Step 2
# randomDots: makes myTurtle draw ntimes random size from 1 to 100 at a random
position.
#
The dots also choose a random color from red,green,and blue.
#
The function also sets th
# Haishan Yuan
# section2_functions_lab 4
# pileUp: this function ask for input from the user 10 times in a row.
#
It accumulates all the input from the user into one long string, and
returns that string.
def pileUp():
acc='
for i in range(10):
message=in
# random.randrange(stop) exclude the stop #.
# random.randrange(start,stop,[step]) [a,b)
ex:random.randrange(5) can be 0 to 4
random.randrange(2,4,2) can be 2
#random.randint(a, b)
[a,b]
ex:random.randint(2,3) can be 2,3
#random.random() floating # [0.0,
Homework 2: CS8, Introduction to Computer Science
Due at the beginning of class on Monday, July 6, 2015
Name: _Haishan Yuan_
UCSBNetID: _Haishan_yuan_
Lab section: _Tuesday 11:00-12:20(2)_
1. What is the definition of the number pi ()?
Pi is defined to be
Homework 3: CS8, Introduction to Computer Science
Due at the beginning of class on Friday, July 10, 2015
Name: _Haishan Yuan_
UCSBNetID: _haishan_yuan_
Lab section: _Tues. 11:00(2)_
1. What is the definition of a string in Python?
Strings are simply seque
Homework 4: CS8, Introduction to Computer Science
Due at the beginning of class on Monday, July 20, 2015
Name: _Haishan Yuan_
UCSBNetID: _haishan_yuan_
Lab section: _Tues. 11:00-12:20_
1. What is the definition of a list in Python?
A list is an ordered, s
Homework 1: CS8, Introduction to Computer Science
Due at the beginning of class on Friday, June 26, 2015
Name: _Haishan Yuan_
UCSBNetID: _Haishan_yuan_
Lab section: _T 11:00AM-12:20PM_
1. What is a Python object?
The one primitive element in Python is the
# Haishan Yuan,Jitao Wang
# CS8, Project 3, Section 2
# cleanup: removes anything that is not a captial letter from message,
#
and returns the resulting string.
def cleanup(message):
newstr="
capL="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for ch in message:
if ch in c
# Haishan Yuan and Jitao Wang
# CS8, Project 4, Lab Sections 2
# potPoints: creates a scatter plot of (x,y) points based on the x and
#
y values in xlist and ylist
def plotPoints(xlist,ylist):
import turtle
a=turtle.Turtle()
lx=min(xlist)-1
ly=min(ylist)-
# Haishan Yuan/Jitao Wang
# CS8, Project 2, Lab Section 2: Tues. 11:00-12:20
# Part 1
# initialize: makes sets the world coordinates to be (-2, -1)
#
in the lower left corner of the screen and (2,1) in the upper right
corner.
#
Hide myTurtle from the scre
# Haishan Yuan
# section 2_functions_lab6
# getTranspript: prompts the user to enter text until the user types 'q'.
#
Every time the user enters text, getTranscript should write the
#
entered text into a file "transcript.txt" in the current working
#
dire