This file contains 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
# Write a program that extracts the last three items in the list sports and assigns it to the variable last. | |
# Make sure to write your code so that it works no matter how many items are in the list. | |
sports = ['cricket', 'football', 'volleyball', 'baseball', 'softball', 'track and field', 'curling', 'ping pong', 'hockey'] | |
last = sports[-3:] |
This file contains 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
# What will the output be for the following code? | |
let = "z" | |
let_two = "p" | |
c = let_two + let | |
m = c*5 | |
print(m) | |
# output |
This file contains 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
# What is the name of jane’s attribute (not method) that is referred to in the following code? | |
import turtle | |
jane = turtle.Turtle() | |
jane.forward(20) | |
print(jane.x) | |
The attribute is |
This file contains 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
# The code below initializes two variables, z and y. | |
# We want to assign the total number of characters in z and in y to the variable a. | |
# Which of the following solutions, if any, would be considered hard coding? | |
z = "hello world" | |
y = "welcome!" | |
a = len("hello worldwelcome!") | |
a = 11 + 8 | |
a = len("hello world") + len("welcome!") |
This file contains 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
#There is a function we are providing in for you in this problem called square. | |
#It takes one integer and returns the square of that integer value. | |
#Write code to assign a variable called xyz the value 5*5 (five squared). | |
#Use the square function, rather than just multiplying with *. | |
xyz = 25 | |
squared = square(xyz) | |
print(squared) |
This file contains 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
# Write code to assign the number of characters in the string rv to a variable num_chars. | |
rv = """Once upon a midnight dreary, while I pondered, weak and weary, | |
Over many a quaint and curious volume of forgotten lore, | |
While I nodded, nearly napping, suddenly there came a tapping, | |
As of some one gently rapping, rapping at my chamber door. | |
'Tis some visitor, I muttered, tapping at my chamber door; | |
Only this and nothing more.""" | |
# Write your code here! |
NewerOlder