Skip to content

Commit cd04a9b

Browse files
committed
first commit
0 parents  commit cd04a9b

Some content is hidden

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

46 files changed

+1245
-0
lines changed

.gitignore

Whitespace-only changes.

PrintingX3.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
days = "Mon Tue Wed Thu Fri Sat Sun"
2+
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
3+
4+
print ("Here are the days: ", days)
5+
print ("Here are the months: ", months)
6+
7+
print ("""
8+
There's something going on here.
9+
We can type a lot of lines.
10+
In fact, we can type as many as we would like.
11+
Like a fourth.
12+
Or a fifth.
13+
Or even a sixth!
14+
""")

SUPERCARS.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#from (filename) import (a specific class)
2+
#use = (specific class).(function inside class)
3+
4+
import scenes #data source
5+
from sys import exit
6+
7+
8+
scenes.opening_scene.intro()
9+
10+
scenes.CarSelection()
11+
12+
scenes.Daytona()
13+
14+
scenes.Annapolis()
15+
16+
scenes.LosAngeles()

WhatWasThat.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tabby_cat = "\tI'm tabbed in"
2+
persian_cat = "I'm split\non a line"
3+
backslash_cat = "I'm \\ a \\ cat"
4+
fat_cat = """
5+
I'll do a list:
6+
\t* Cat Food
7+
\t* Fishies
8+
\t* Catnip\n\t* Grass
9+
"""
10+
11+
print (tabby_cat)
12+
print (persian_cat)
13+
print (backslash_cat)
14+
print (fat_cat)

__pycache__/SUPERCARS.cpython-36.pyc

567 Bytes
Binary file not shown.

__pycache__/game_help.cpython-36.pyc

375 Bytes
Binary file not shown.

__pycache__/input.cpython-36.pyc

338 Bytes
Binary file not shown.

__pycache__/scenes.cpython-36.pyc

10.7 KB
Binary file not shown.

__pycache__/scenes.cpython-37.pyc

10.8 KB
Binary file not shown.

cars.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cars = 100
2+
space = 4.0
3+
drivers = 30
4+
passengers = 90
5+
cars_not_driven = cars - drivers
6+
cars_driven = drivers
7+
carpool_capacity = cars_driven * space
8+
average_passengers_per_car = passengers / cars_driven
9+
10+
print ("there are", cars, "cars available")
11+

ex1.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("is 7+2>3+4?", 7+2>3+4)

ex13.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from sys import argv
2+
# read WYSS section for how to run this
3+
script, first, second, third = argv
4+
5+
print("This script is called:", script)
6+
print("Your first variable is:", first)
7+
print("Your second variable is:", second)
8+
print("Your third variable is:", third)

ex14.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sys import argv
2+
3+
script, user_name = argv
4+
prompt = '> '
5+
6+
print(f"Hi {user_name}, I'm the {script} script.")
7+
print("I'd like to ask some questions.")
8+
print(f"Do you like me {user_name}?")
9+
likes = input(prompt)
10+
11+
print(f"Where do you live, {user_name}?")
12+
lives = input(prompt)
13+
14+
print("What kind of computer do you have?")
15+
computer = input(prompt)
16+
17+
print(f"""
18+
Alright, so you said {likes} to liking me.
19+
You live in {lives}. Not sure where that is... estimated 00:23:00 till gps location lock.
20+
And you have a {computer}. Nice.
21+
""")

ex15.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from sys import argv
2+
3+
script, filename = argv
4+
5+
txt = open(filename)
6+
7+
print(f"Here's your file {filename}:")
8+
print(txt.read())
9+
10+
print("Type the filename again:")
11+
file_again = input("> ")
12+
13+
txt_again = open(file_again)
14+
15+
print(txt_again.read())

ex15_sample.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This file has some cool stiff in it.
2+
It has stuff like this.
3+
Ya see? Lots of cool stuff.
4+
Super cool.

ex16.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from sys import argv
2+
3+
script, filename = argv
4+
5+
print(f"We're going to erase {filename}.")
6+
print("If you don't want that, hit CTRL-C.")
7+
print("If you do want that, hit enter/return.")
8+
input("?")
9+
10+
print("Opening the file...")
11+
target = open(filename, 'w')
12+
13+
print("Truncating the file. Goodbye!")
14+
target.truncate()
15+
16+
print("Now I'm going to ask for three lines")
17+
18+
line1 = input("line 1: ")
19+
line2 = input("line 2: ")
20+
line3 = input("line 3: ")
21+
22+
print(f"I'll write those to {filename}.")
23+
24+
target.write(f"""
25+
{line1}
26+
{line2}
27+
{line3}
28+
""")
29+
30+
print("And finally, we close it.")
31+
target.close()

ex17.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from sys import argv
2+
from os.path import exists
3+
4+
script, from_file, to_file = argv
5+
6+
print(f"Copying from {from_file} to {to_file}.")
7+
8+
in_file = open(from_file)
9+
indata = in_file.read()
10+
11+
print(f"The input file is {len(indata)} bytes long.")
12+
13+
print(f"Does the output file exist? {exists(to_file)}")
14+
print("Ready, hit RETURN/ENTER to continue, or CTRL-C to abort.")
15+
input()
16+
17+
out_file = open(to_file, 'w')
18+
out_file.write(indata)
19+
20+
print("Alright, task complete.")
21+
22+
out_file.close()
23+
in_file.close()

ex18.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def print_two(*args):
2+
arg1, arg2 = args
3+
print(f"arg1: {arg1}, arg2: {arg2}")
4+
5+
def print_two_again(arg1, arg2):
6+
print(f"arg1: {arg1}, arg2: {arg2}")
7+
8+
def print_one(arg1):
9+
print(f"arg1: {arg1}")
10+
11+
def print_none():
12+
print("I got nothin'.")
13+
14+
print_two("Rex", "McAllister")
15+
print_two_again("Rex", "McAllister")
16+
print_one("Whatever we want")
17+
print_none()

ex19.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def cheese_and_crackers(cheese_count, boxes_of_crackers):
2+
print(f"You have {cheese_count} cheeses.")
3+
print(f"You have {boxes_of_crackers} boxes of crackers.")
4+
print("Man, thats enough for a party!")
5+
print("Get a blanket.\n")
6+
7+
print("We can give function numbers directly.")
8+
amount_of_cheese = 10
9+
amount_of_crackers = 50
10+
11+
cheese_and_crackers(amount_of_cheese, amount_of_crackers)
12+
13+
print("We can even do math inside too:")
14+
cheese_and_crackers(10 + 20, 5 + 6)
15+
16+
print("And we can combine the two (variable & math)...")
17+
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)

ex2.py.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
print ("I will now count my chickens:")
2+
3+
print ("hens", 25 + 30 / 6)
4+
print ("roosters", 100 - 25 * 3 % 4)
5+
6+
print ("Now I will count the eggs:")
7+
8+
print (3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
9+
10+
print ("Is it true that 2 + 2 < 5 - 7?")
11+
12+
print (3 + 2 < 5 - 7)
13+
14+
print ("What is 3 + 2?", 3 + 2)
15+
print ("what is 5 - 7?", 5 - 7)
16+
17+
print ("Oh, OK, that's why it's false.")
18+
19+
print ("How about I try some more.")
20+
21+
print (5 < 7)
22+
print (5 > 7)

ex20.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from sys import argv
2+
3+
script, input_file = argv
4+
5+
def print_all(f):
6+
print(f.read())
7+
8+
def rewind(f):
9+
f.seek(0)
10+
11+
def print_a_line(line_count, f):
12+
print(line_count, f.readline())
13+
14+
15+
current_file = open(input_file)
16+
17+
print("First lets print the whole file:\n")
18+
19+
print_all(current_file)
20+
21+
print("Now let's rewind, kinda like a tape")
22+
23+
rewind(current_file)
24+
25+
print("Lets print three lines:")
26+
27+
current_line = 1
28+
print_a_line(current_line, current_file)
29+
30+
current_line = current_line + 1
31+
print_a_line(current_line, current_file)
32+
33+
current_line = current_line + 1
34+
print_a_line(current_line, current_file)

ex21.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def add(a, b):
2+
print(f"ADDING {a} + {b}")
3+
return a + b
4+
5+
def subtract(a, b):
6+
print(f"SUBTRACTING {a} - {b}")
7+
return a - b
8+
9+
def multiply(a, b):
10+
print(f"MULTIPLYING {a} * {b}")
11+
return a * b
12+
13+
def divide(a, b):
14+
print(f"DIVIDING {a}, {b}")
15+
return a / b
16+
17+
age = add(30, 5)
18+
height = subtract(78, 4)
19+
weight = multiply(90, 2)
20+
iq = divide(100, 2)
21+
22+
print(f"Age: {age}, Height: {height}, Weight: {height}, IQ: {iq}")
23+
24+
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
25+
26+
print("That becomes: ", what, "Can you do it by hand?")

ex22.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
script, encoding, error = sys.argv
3+
4+
5+
def main(language_file, encoding, errors):
6+
line = language_file.readline()
7+
8+
if line:
9+
print_line(line, encoding, errors)
10+
return main(language_file, encoding, errors)
11+
12+
13+
14+
def print_line(line, encoding, errors):
15+
next_lang = line.strip()
16+
raw_bytes = next_lang.encode(encoding, errors=errors)
17+
cooked_string = raw_bytes.decode(encoding, errors=errors)
18+
19+
print(raw_bytes, "<===>", cooked_string)
20+
21+
22+
23+
languages = open("languages.txt", encoding="utf-8" )
24+
25+
main(languages, encoding, error)

ex24.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#This is an exercise of everything I've learned so far.
2+
3+
print("Let's practice everything.")
4+
print('You\'d need to know \'bout escapes with \\ that do:')
5+
print('\n newlines and \t tabs.')
6+
7+
poem = """
8+
\tThe lovely world
9+
with logic so firmly planted
10+
cannot discern \n the needs of love
11+
nor comprehend passion from intuition
12+
and requires an explanation
13+
\n\twhere there is none.
14+
"""
15+
16+
print("-" * 10)
17+
print(poem)
18+
print("-" * 10)
19+
20+
21+
22+
five = 10 - 2 + 3 - 6
23+
print(f"This should be 5: {five}")
24+
25+
def secret_formula(started):
26+
jelly_beans = started * 500
27+
jars = jelly_beans / 1000
28+
crates = jars / 100
29+
return jelly_beans, jars, crates
30+
31+
32+
start_point = 1000
33+
beans, jars, crates = secret_formula(start_point)
34+
35+
#remember that this is another way to format a string:
36+
37+
print("with a starting point of: {}".format(start_point))
38+
39+
#it's just like f""
40+
41+
print(f"We'd have {beans} beans. {jars} jars, and {crates} crates")
42+
43+
start_point = start_point / 10
44+
45+
print("We can also do that this way.")
46+
formula = secret_formula(start_point)
47+
#this is an easy way to apply a list to a format string
48+
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))

0 commit comments

Comments
 (0)