Open
Conversation
|
|
||
| # Print out the version of Python you're using: | ||
| # YOUR CODE HERE | ||
| print(sys.version) |
Collaborator
There was a problem hiding this comment.
# 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}')
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)) |
Collaborator
There was a problem hiding this comment.
# 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 |
Collaborator
There was a problem hiding this comment.
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] |
Collaborator
There was a problem hiding this comment.
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) |
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): |
Collaborator
There was a problem hiding this comment.
Here you defined and declared the same function again.
|
|
||
| # Output the second element: 4: | ||
| print() | ||
| y= a[1:2] |
|
|
||
| # Output the last three elements in the array: [7, 9, 6] | ||
| print() | ||
| z = a[3:] |
|
|
||
| # Output the second-to-last element: 9 | ||
| print() | ||
| x= a[4:5] |
| # Write a list comprehension to produce the array [1, 2, 3, 4, 5] | ||
|
|
||
| y = [] | ||
| y = [x+1 for x in range(5)] |
Collaborator
There was a problem hiding this comment.
y = [num for num in range(1, 6)]
| a = ["foo", "bar", "baz"] | ||
|
|
||
| y = [] | ||
| y = [str(a[x]).upper() for x in range(len(a))] |
Collaborator
There was a problem hiding this comment.
y = [word.upper() for word in a]
| return False | ||
|
|
||
| # Read a number from the keyboard | ||
| num = input("Enter a number: ") |
Collaborator
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
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: |
Collaborator
There was a problem hiding this comment.
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 | |||
| @@ -20,11 +22,12 @@ def outer(): | |||
|
|
|||
| def inner(): | |||
| y = 999 | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.