Skip to content

Kyle teeter - #1

Open
kyleteeter wants to merge 19 commits into
masterfrom
KyleTeeter
Open

kyleteeter wants to merge 19 commits into
masterfrom
KyleTeeter

Conversation

@kyleteeter

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/03_modules.py

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Print out the version of Python you're using:
# YOUR CODE HERE

major = sys.version_info[0]
minor = sys.version_info[1]
micro = sys.version_info[2]

print(f'The version of python you are using is: {major}.{minor}.{micro}')

Comment thread src/04_printing.py Outdated
# 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 %s, y is %s, z is %s" % (x, y, z))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Using the printf operator (f), 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(f'x is {x}, y is {round(y, 2)}, z is {z}')

Comment thread src/04_printing.py
# Finally, print the same thing using an f-string No newline at end of file
# Finally, print the same thing using an f-string

print (f"x is {x}, y is {yRound}, z is {z}") No newline at end of file

@eddygonzalez9708 eddygonzalez9708 May 30, 2019 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in this module. The last printing exercise should be like the following:

# Using %-formatting to print the same thing

print('x is %d, y is %.2f, z is %s' %(x, round(y, 2), z))

Comment thread src/05_lists.py

# Change x so that it is [1, 2, 3, 4, 9, 10]
# YOUR CODE HERE
del x[4]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use:

x.pop(4)

Comment thread src/06_tuples.py

# Declare a tuple of 1 element then print it
u = (1) # What needs to be added to make this work?
u = (1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u = (1,)

Comment thread src/06_tuples.py Outdated
# Declare a tuple of 1 element then print it
u = (1) # What needs to be added to make this work?
u = (1)
def print_tuple(u):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you defined and declared the same function again.

Comment thread src/07_slices.py

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(a[1])

Comment thread src/07_slices.py

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

@eddygonzalez9708 eddygonzalez9708 May 30, 2019 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(a[-3])

Comment thread src/07_slices.py

# Output the second-to-last element: 9
print()
x= a[4:5]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(a[-2])

Comment thread src/08_comprehensions.py
# Write a list comprehension to produce the array [1, 2, 3, 4, 5]

y = []
y = [x+1 for x in range(5)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/08_comprehensions.py
a = ["foo", "bar", "baz"]

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/10_functions.py
return False

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num = int(input("Enter a number: "))

Comment thread src/11_args.py

# What thing do you have to add to make this work?
# check to see if the argument is a list item or add * in front of a
print(f2(a)) # Should print 22

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your f2 function and print statement can be defined like the following:

def f2(*argv):
  return sum(argv)

print(f2(*a))

Comment thread src/11_args.py

# YOUR CODE HERE
def f4(**kwargs):
for key in kwargs:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your for loop can also be defined like the following for simplicity:

for key, val in kwargs.items():
    print('key: %s, value: %s' %(key, val))

Comment thread src/12_scopes.py
@@ -6,10 +6,12 @@

def changeX():
x = 99

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global x

Comment thread src/12_scopes.py
@@ -20,11 +22,12 @@ def outer():

def inner():
y = 999

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonlocal y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants