Skip to content

Comments

Kyle teeter#1

Open
kyleteeter wants to merge 19 commits intomasterfrom
KyleTeeter
Open

Kyle teeter#1
kyleteeter wants to merge 19 commits intomasterfrom
KyleTeeter

Conversation

@kyleteeter
Copy link
Owner

No description provided.


# Print out the version of Python you're using:
# YOUR CODE HERE
print(sys.version)
Copy link
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}')

# 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
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}')

# 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
Copy link
Collaborator

@eddygonzalez9708 eddygonzalez9708 May 30, 2019

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))


# Change x so that it is [1, 2, 3, 4, 9, 10]
# YOUR CODE HERE
del x[4]
Copy link
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)


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

Choose a reason for hiding this comment

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

u = (1,)

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
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.


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

Choose a reason for hiding this comment

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

print(a[1])


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

@eddygonzalez9708 eddygonzalez9708 May 30, 2019

Choose a reason for hiding this comment

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

print(a[-3])


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

Choose a reason for hiding this comment

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

print(a[-2])

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

y = []
y = [x+1 for x in range(5)]
Copy link
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)]

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

y = []
y = [str(a[x]).upper() for x in range(len(a))]
Copy link
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]

return False

# Read a number from the keyboard
num = input("Enter a number: ")
Copy link
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: "))


# 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
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))


# YOUR CODE HERE
def f4(**kwargs):
for key in kwargs:
Copy link
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))

@@ -6,10 +6,12 @@

def changeX():
x = 99
Copy link
Collaborator

Choose a reason for hiding this comment

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

global x

@@ -20,11 +22,12 @@ def outer():

def inner():
y = 999
Copy link
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