Skip to content

Module_2/Assignment completed #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions .idea/Intro-Python-I.iml

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

3 changes: 3 additions & 0 deletions .idea/dictionaries/Julio.xml

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

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

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

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

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

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

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

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

91 changes: 91 additions & 0 deletions .idea/workspace.xml

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

3 changes: 2 additions & 1 deletion src/00_hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# 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)
5 changes: 3 additions & 2 deletions src/02_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# Write a print statement that combines x + y into the integer value 12

# YOUR CODE HERE

print(int(y)+x)

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

# YOUR CODE HERE
# YOUR CODE HERE
print(str(x)+y)
11 changes: 6 additions & 5 deletions src/03_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@

# Print out the command line arguments in sys.argv, one per line:
# YOUR CODE HERE

print(sys.argv)
# Print out the OS platform you're using:
# YOUR CODE HERE

print(sys.platform)
# Print out the version of Python you're using:
# YOUR CODE HERE

print(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(os.getpid())
# Print the current working directory (cwd):
# YOUR CODE HERE

print(os.getcwd())
# Print out your machine's login name
# YOUR CODE HERE
print(os.getlogin())
5 changes: 3 additions & 2 deletions src/04_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# 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'" % (x,y,z))
# Use the 'format' string method to print the same thing

# Finally, print the same thing using an f-string
# Finally, print the same thing using an f-string
print(f"x is {x},y is {y},z is '{z}'")
14 changes: 8 additions & 6 deletions src/05_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

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

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

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

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

# Print the length of list x
# YOUR CODE HERE

print(len(x))
# Print all the values in x multiplied by 1000
# YOUR CODE HERE
# YOUR CODE HERE
for i in x:
print(i*1000)
7 changes: 6 additions & 1 deletion src/06_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ def dist(a, b):

# YOUR CODE HERE

def print_tuple(t):
for x in t:
print(x)


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[3])

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

# 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[:-2])

# For string s...

s = "Hello, world!"

# Output just the 8th-12th characters: "world"
print()
print(s[7:12])
8 changes: 4 additions & 4 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+1 for x in range(5)]

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(9)]

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 = [int(a) for a in x if int(a) % 2 == 0]

print(y)
15 changes: 13 additions & 2 deletions src/09_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@

# Add a new waypoint to the list
# YOUR CODE HERE

new_waypoint = {
'lat': 26,
'lon': -214,
'name': 'a fourth place'
}
waypoints.append(new_waypoint)
print(waypoints)
# 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
waypoints[0]['lon'] = -130
waypoints[0]['name'] = 'not a real place'
print(waypoints)

# Write a loop that prints out all the field values for all the waypoints
# YOUR CODE HERE
# YOUR CODE HERE
for x in range(len(waypoints)):
print(waypoints[x].values())
15 changes: 13 additions & 2 deletions src/10_functions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# Write a function is_even that will return true if the passed-in number is even.

# YOUR CODE HERE
def is_true(num):
if num % 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"

def is_even(num):
if num % 2 == 0:
print("Even!")
else:
print("Odd!")
# YOUR CODE HERE

is_even(num)
print(is_true(num))
Loading