Skip to content

Instantly share code, notes, and snippets.

View ashutoshpipriye's full-sized avatar
:octocat:
Learning

Ashutosh Pipriye ashutoshpipriye

:octocat:
Learning
View GitHub Profile
# 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!
#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)
# 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!")
# 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
# What will the output be for the following code?
let = "z"
let_two = "p"
c = let_two + let
m = c*5
print(m)
# output
# 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:]
# Write code that combines the following variables so that the sentence
# “You are doing a great job, keep it up!” is assigned to the variable message.
# Do not edit the values assigned to by, az, io, or qy.
by = "You are"
az = "doing a great "
io = "job"
qy = "keep it up!"
message = (by+' '+az+io+','+' '+qy)
print(message)
# What will the output be for the following code?
ls = ['run', 'world', 'travel', 'lights', 'moon', 'baseball', 'sea']
new = ls[2:4]
print(new)
# output
['travel', 'lights']
# python is a zero-index based language and slices are inclusive of the first index and exclusive of the second.
# Write one for loop to print out each character of the string my_str on a separate line.
my_str = "MICHIGAN"
for i in range(len(my_str)):
print(my_str[i])
# Write one for loop to print out each element of the list several_things.
# Then, write another for loop to print out the TYPE of each element of the list several_things.
# To complete this problem you should have written two different for loops,
# each of which iterates over the list several_things, but each of those 2 for loops should have a different result.
several_things = ["hello", 2, 4, 6.0, 7.5, 234352354, "the end", "", 99]
for i in range(len(several_things)):
print(several_things[i])
for j in range(len(several_things)):