Skip to content

Commit 5afedd6

Browse files
committed
Add online materials.
1 parent 5b281d3 commit 5afedd6

File tree

99 files changed

+49723
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+49723
-0
lines changed

automate_online-materials/alarm.wav

569 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
print('Enter the name of cat 1:')
2+
catName1 = input()
3+
print('Enter the name of cat 2:')
4+
catName2 = input()
5+
print('Enter the name of cat 3:')
6+
catName3 = input()
7+
print('Enter the name of cat 4:')
8+
catName4 = input()
9+
print('Enter the name of cat 5:')
10+
catName5 = input()
11+
print('Enter the name of cat 6:')
12+
catName6 = input()
13+
print('The cat names are:')
14+
print(catName1 + ' ' + catName2 + ' ' + catName3 + ' ' + catName4 + ' ' + catName5 + ' ' + catName6)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
catNames = []
2+
while True:
3+
print('Enter the name of cat ' + str(len(catNames) + 1) + ' (Or enter nothing to stop.):')
4+
name = input()
5+
if name == '':
6+
break
7+
catNames = catNames + [name] # list concatenation
8+
print('The cat names are:')
9+
for name in catNames:
10+
print(' ' + name)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! python3
2+
# backupToZip.py
3+
# Copies an entire folder and its contents into
4+
# a zip file whose filename increments.
5+
6+
import zipfile, os
7+
8+
def backupToZip(folder):
9+
# Backup the entire contents of "folder" into a zip file.
10+
11+
folder = os.path.abspath(folder) # make sure folder is absolute
12+
13+
# Figure out the filename this code should used based on
14+
# what files already exist.
15+
number = 1
16+
while True:
17+
zipFilename = os.path.basename(folder) + '_' + str(number) + '.zip'
18+
if not os.path.exists(zipFilename):
19+
break
20+
number = number + 1
21+
22+
# Create the zip file.
23+
print('Creating %s...' % (zipFilename))
24+
backupZip = zipfile.ZipFile(zipFilename, 'w')
25+
26+
# Walk the entire folder tree and compress the files in each folder.
27+
for foldername, subfolders, filenames in os.walk(folder):
28+
print('Adding files in %s...' % (foldername))
29+
# Add the current folder to the ZIP file.
30+
backupZip.write(foldername)
31+
32+
# Add all the files in this folder to the ZIP file.
33+
for filename in filenames:
34+
if filename.startswith(os.path.basename(folder) + '_') and filename.endswith('.zip'):
35+
continue # don't backup the backup ZIP files
36+
backupZip.write(os.path.join(foldername, filename))
37+
backupZip.close()
38+
print('Done.')
39+
40+
41+
backupToZip('C:\\delicious')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
2+
3+
while True:
4+
print('Enter a name: (blank to quit)')
5+
name = input()
6+
if name == '':
7+
break
8+
9+
if name in birthdays:
10+
print(birthdays[name] + ' is the birthday of ' + name)
11+
else:
12+
print('I do not have birthday information for ' + name)
13+
print('What is their birthday?')
14+
bday = input()
15+
birthdays[name] = bday
16+
print('Birthday database updated.')

automate_online-materials/boxPrint.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def boxPrint(symbol, width, height):
2+
if len(symbol) != 1:
3+
raise Exception('Symbol must be a single character string.')
4+
if width <= 2:
5+
raise Exception('Width must be greater than 2.')
6+
if height <= 2:
7+
raise Exception('Height must be greater than 2.')
8+
9+
print(symbol * width)
10+
for i in range(height - 2):
11+
print(symbol + (' ' * (width - 2)) + symbol)
12+
print(symbol * width)
13+
14+
for sym, w, h in (('*', 4, 4), ('O', 20, 5), ('x', 1, 3), ('ZZ', 3, 3)):
15+
try:
16+
boxPrint(sym, w, h)
17+
except Exception as err:
18+
print('An exception happened: ' + str(err))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
print('Enter the first number to add:')
2+
first = input()
3+
print('Enter the second number to add:')
4+
second = input()
5+
print('Enter the third number to add:')
6+
third = input()
7+
print('The sum is ' + first + second + third)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! python3
2+
# Adds Wikipedia bullet points to the start
3+
# of each line of text on the clipboard.
4+
5+
import pyperclip
6+
text = pyperclip.paste()
7+
8+
#Separate lines and add stars.
9+
lines = text.split('\n')
10+
for i in range(len(lines)): # loop through all indexes for "lines" list
11+
lines[i] = '* ' + lines[i] # add star to each string in "lines" list
12+
text = '\n'.join(lines)
13+
pyperclip.copy(text)

automate_online-materials/calcProd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import time
2+
startTime = time.time()
3+
# Calculate the product of the first 100,000 numbers.
4+
product = 1
5+
for i in range(1, 100000):
6+
product = product * i
7+
endTime = time.time()
8+
print('The result is %s digits long.' % (len(str(product))))
9+
print('Took %s seconds to calculate.' % (endTime - startTime))

automate_online-materials/catlogo.png

16.3 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
print('''Dear Alice,
2+
3+
Eve's cat has been arrested for catnapping, cat burglary, and extortion.
4+
5+
Sincerely,
6+
Bob''')

0 commit comments

Comments
 (0)