Skip to content

Commit

Permalink
Add online materials.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguohui committed Jun 27, 2017
1 parent 5b281d3 commit 5afedd6
Show file tree
Hide file tree
Showing 99 changed files with 49,723 additions and 0 deletions.
Binary file added automate_online-materials/alarm.wav
Binary file not shown.
14 changes: 14 additions & 0 deletions automate_online-materials/allMyCats1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
print('Enter the name of cat 1:')
catName1 = input()
print('Enter the name of cat 2:')
catName2 = input()
print('Enter the name of cat 3:')
catName3 = input()
print('Enter the name of cat 4:')
catName4 = input()
print('Enter the name of cat 5:')
catName5 = input()
print('Enter the name of cat 6:')
catName6 = input()
print('The cat names are:')
print(catName1 + ' ' + catName2 + ' ' + catName3 + ' ' + catName4 + ' ' + catName5 + ' ' + catName6)
10 changes: 10 additions & 0 deletions automate_online-materials/allMyCats2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
catNames = []
while True:
print('Enter the name of cat ' + str(len(catNames) + 1) + ' (Or enter nothing to stop.):')
name = input()
if name == '':
break
catNames = catNames + [name] # list concatenation
print('The cat names are:')
for name in catNames:
print(' ' + name)
41 changes: 41 additions & 0 deletions automate_online-materials/backupToZip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! python3
# backupToZip.py
# Copies an entire folder and its contents into
# a zip file whose filename increments.

import zipfile, os

def backupToZip(folder):
# Backup the entire contents of "folder" into a zip file.

folder = os.path.abspath(folder) # make sure folder is absolute

# Figure out the filename this code should used based on
# what files already exist.
number = 1
while True:
zipFilename = os.path.basename(folder) + '_' + str(number) + '.zip'
if not os.path.exists(zipFilename):
break
number = number + 1

# Create the zip file.
print('Creating %s...' % (zipFilename))
backupZip = zipfile.ZipFile(zipFilename, 'w')

# Walk the entire folder tree and compress the files in each folder.
for foldername, subfolders, filenames in os.walk(folder):
print('Adding files in %s...' % (foldername))
# Add the current folder to the ZIP file.
backupZip.write(foldername)

# Add all the files in this folder to the ZIP file.
for filename in filenames:
if filename.startswith(os.path.basename(folder) + '_') and filename.endswith('.zip'):
continue # don't backup the backup ZIP files
backupZip.write(os.path.join(foldername, filename))
backupZip.close()
print('Done.')


backupToZip('C:\\delicious')
16 changes: 16 additions & 0 deletions automate_online-materials/birthdays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}

while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
break

if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
else:
print('I do not have birthday information for ' + name)
print('What is their birthday?')
bday = input()
birthdays[name] = bday
print('Birthday database updated.')
18 changes: 18 additions & 0 deletions automate_online-materials/boxPrint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def boxPrint(symbol, width, height):
if len(symbol) != 1:
raise Exception('Symbol must be a single character string.')
if width <= 2:
raise Exception('Width must be greater than 2.')
if height <= 2:
raise Exception('Height must be greater than 2.')

print(symbol * width)
for i in range(height - 2):
print(symbol + (' ' * (width - 2)) + symbol)
print(symbol * width)

for sym, w, h in (('*', 4, 4), ('O', 20, 5), ('x', 1, 3), ('ZZ', 3, 3)):
try:
boxPrint(sym, w, h)
except Exception as err:
print('An exception happened: ' + str(err))
7 changes: 7 additions & 0 deletions automate_online-materials/buggyAddingProgram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print('Enter the first number to add:')
first = input()
print('Enter the second number to add:')
second = input()
print('Enter the third number to add:')
third = input()
print('The sum is ' + first + second + third)
13 changes: 13 additions & 0 deletions automate_online-materials/bulletPointAdder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! python3
# Adds Wikipedia bullet points to the start
# of each line of text on the clipboard.

import pyperclip
text = pyperclip.paste()

#Separate lines and add stars.
lines = text.split('\n')
for i in range(len(lines)): # loop through all indexes for "lines" list
lines[i] = '* ' + lines[i] # add star to each string in "lines" list
text = '\n'.join(lines)
pyperclip.copy(text)
9 changes: 9 additions & 0 deletions automate_online-materials/calcProd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import time
startTime = time.time()
# Calculate the product of the first 100,000 numbers.
product = 1
for i in range(1, 100000):
product = product * i
endTime = time.time()
print('The result is %s digits long.' % (len(str(product))))
print('Took %s seconds to calculate.' % (endTime - startTime))
Binary file added automate_online-materials/catlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions automate_online-materials/catnapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
print('''Dear Alice,
Eve's cat has been arrested for catnapping, cat burglary, and extortion.
Sincerely,
Bob''')
Loading

0 comments on commit 5afedd6

Please sign in to comment.