Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/.idea/src.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/00_hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Print "Hello, world!" to your terminal
# Print "Hello, world!" to your terminal

print("Hello, World!")
3 changes: 2 additions & 1 deletion src/01_bignum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Print out 2 to the 65536 power
# (try doing the same thing in the JS console and see what it outputs)

# YOUR CODE HERE
# YOUR CODE HERE
print(2**65536)
4 changes: 2 additions & 2 deletions src/02_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
y = "7"

# Write a print statement that combines x + y into the integer value 12

print(x+int(y))
# YOUR CODE HERE


# Write a print statement that combines x + y into the string value 57

print(f"{str(x)}{y}")
# YOUR CODE HERE
10 changes: 9 additions & 1 deletion src/03_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@
"""

import sys
import os
# See docs for the sys module: https://docs.python.org/3.7/library/sys.html

# Print out the command line arguments in sys.argv, one per line:
# YOUR CODE HERE
for arg in sys.argv[1:]:
print(arg)

# Print out the OS platform you're using:
# YOUR CODE HERE

print(f"Operating system: {os.name}")

# Print out the version of Python you're using:
# YOUR CODE HERE
print(f"Python Version: {sys.version}")


import os
# See the docs for the OS module: https://docs.python.org/3.7/library/os.html

# Print the current process ID
# YOUR CODE HERE
print(f"Process ID: {os.getpid()}")

# Print the current working directory (cwd):
# YOUR CODE HERE
print(f"Current directory: {os.getcwd()}")

# Print out your machine's login name
# YOUR CODE HERE
print(f"Machine Login: {os.getlogin()}")
5 changes: 4 additions & 1 deletion src/04_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
# Using the printf operator (%), print the following feeding in the values of x,
# y, and z:
# x is 10, y is 2.25, z is "I like turtles!"
print("x is %d, y is %f, z is %s" % (10, 2.25, "I like turtles!"))

# Use the 'format' string method to print the same thing
print("x is {}, y is {}, z is {}".format(10, 2.25, "I like turtles!"))

# Finally, print the same thing using an f-string
# Finally, print the same thing using an f-string
print(f"x is {10}, y is {2.25}, z is I like turtles!")
7 changes: 7 additions & 0 deletions src/05_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@
# For the following, DO NOT USE AN ASSIGNMENT (=).

# Change x so that it is [1, 2, 3, 4]
x.append(4)
# YOUR CODE HERE
print(x)

# Using y, change x so that it is [1, 2, 3, 4, 8, 9, 10]
x.extend(y)
# YOUR CODE HERE
print(x)

# Change x so that it is [1, 2, 3, 4, 9, 10]
x.remove(8)
# YOUR CODE HERE
print(x)

# Change x so that it is [1, 2, 3, 4, 9, 99, 10]
x.insert(5, 99)
# YOUR CODE HERE
print(x)

# Print the length of list x
# YOUR CODE HERE
print(len(x))

# Print all the values in x multiplied by 1000
for y in x:
print(y*1000)
# YOUR CODE HERE
14 changes: 9 additions & 5 deletions src/06_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@

import math


def dist(a, b):
"""Compute the distance between two x,y points."""
x0, y0 = a # Destructuring assignment
x1, y1 = b

return math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
return math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2)


a = (2, 7) # <-- x,y coordinates stored in tuples
a = (2, 7) # <-- x,y coordinates stored in tuples
b = (-14, 72)

# Prints "Distance is 66.94"
print("Distance is: {:.2f}".format(dist(a, b)))



# Write a function `print_tuple` that prints all the values in a tuple

# YOUR CODE HERE
def print_tuple(x):
for tuplet in x:
print(tuplet)


t = (1, 2, 5, 7, 99)
print_tuple(t) # Prints 1 2 5 7 99, one per line

# Declare a tuple of 1 element then print it
u = (1) # What needs to be added to make this work?
u = (1,) # What needs to be added to make this work?
print_tuple(u)
14 changes: 7 additions & 7 deletions src/07_slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
a = [2, 4, 1, 7, 9, 6]

# Output the second element: 4:
print()
print(a[1:2])

# Output the second-to-last element: 9
print()
print(a[-2:-1])

# Output the last three elements in the array: [7, 9, 6]
print()
print(a[-3:])

# Output the two middle elements in the array: [1, 7]
print()
print(a[2:4])

# Output every element except the first one: [4, 1, 7, 9, 6]
print()
print(a[1:])

# Output every element except the last one: [2, 4, 1, 7, 9]
print()
print(a[:-1])

# For string s...

s = "Hello, world!"

# Output just the 8th-12th characters: "world"
print()
print(s[7:12])
10 changes: 5 additions & 5 deletions src/08_comprehensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

# Write a list comprehension to produce the array [1, 2, 3, 4, 5]

y = []
y = [x for x in range(1,6)]

print (y)
print(y)

# Write a list comprehension to produce the cubes of the numbers 0-9:
# [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

y = []
y = [x**3 for x in range (0,10)]

print(y)

Expand All @@ -26,7 +26,7 @@

a = ["foo", "bar", "baz"]

y = []
y = [x.upper() for x in a]

print(y)

Expand All @@ -36,6 +36,6 @@
x = input("Enter comma-separated numbers: ").split(',')

# What do you need between the square brackets to make it work?
y = []
y = [eve for eve in x if int(eve) % 2 == 0]

print(y)
18 changes: 17 additions & 1 deletion src/09_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,29 @@

# Add a new waypoint to the list
# YOUR CODE HERE
x = {
"lat": 55,
"lon": -132,
"name": "a fourth place"
}

waypoints.append(x)

# Modify the dictionary with name "a place" such that its longitude
# value is -130 and change its name to "not a real place"
# Note: It's okay to access the dictionary using bracket notation on the
# waypoints list.

# YOUR CODE HERE
replacement = {'lon': -130,
'name': 'not a real place'
}

waypoints[0].update(replacement)


# Write a loop that prints out all the field values for all the waypoints
# YOUR CODE HERE
# YOUR CODE HERE
for dicts in waypoints:
for key, value in dicts.items():
print(f"{key}\'s value: {value}")
17 changes: 17 additions & 0 deletions src/10_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

# YOUR CODE HERE


def is_even(x):
if x % 2 == 0:
return True
else:
return False


# Read a number from the keyboard
num = input("Enter a number: ")
num = int(num)


# Print out "Even!" if the number is even. Otherwise print "Odd"

# YOUR CODE HERE
def tester(x):
test_even = is_even(x)

if test_even:
print("Even!")
else:
print("Odd")

tester(num)
Loading