Codecademy python
14884 ワード
#1
#2
#3
#4
#5
#6
#7
#8
#9
#10
#11
#12
#13
#14
#15
#16
#17
#18
#19
#20
#21
#22
#23
#24
#25
#26
#27
#28
#29
#30
#31
#32
#33
#34
#35
print "Welcome to Python!"
#2
my_variable = 10
#3
# Set the variables to the values listed in the instructions!
my_int = 7
my_float = 1.23
my_bool = True
#4
# my_int is set to 7 below. What do you think
# will happen if we reset it to 3 and print the result?
my_int = 7
# Change the value of my_int to 3 on line 8!
my_int = 3
# Here's some code that will print my_int to the console:
# The print keyword will be covered in detail soon!
print my_int
#5
def spam():
eggs = 12
return eggs
print spam()
#6
def spam():
eggs = 12
return eggs
print spam()
#7
spam = True
eggs = False
#8
#fuck you
mysterious_variable = 42
#9
"""233
"""
#10
# Set count_to equal to the sum of two big numbers
count_to = 100+1000
print count_to
#11
#Set eggs equal to 100 using exponentiation on line 3!
eggs = 10**2
print eggs
#12
#Set spam equal to 1 using modulo on line 3!
spam = 5 % 4
print spam
#13
#fuck you
monty = True
python = 1.234
monty_python = python**2
#14
# Assign the variable meal the value 44.50 on line 3!
meal = 44.50
#15
meal = 44.50
tax = 6.75 / 100
#16
# You're almost there! Assign the tip variable on line 5.
meal = 44.50
tax = 0.0675
tip = 15.0 / 100
#17
# Reassign meal on line 7!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal + meal*tax
#18
# Assign the variable total on line 8!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal + meal * tax
total = meal + meal * tip
print("%.2f" % total)
#19
# Set the variable brian on line 3!
brian = "Hello life!"
#20
# Assign your variables below, each on its own line!
caesar = "Graham"
praline = "John"
viking = "Teresa"
# Put your variables above this line
print caesar
print praline
print viking
#21
# The string below is broken. Fix it using the escape backslash!
'This isn\'t flying, this is falling with style!'
#22
"""
The string "PYTHON" has six characters,
numbered 0 to 5, as shown below:
+---+---+---+---+---+---+
| P | Y | T | H | O | N |
+---+---+---+---+---+---+
0 1 2 3 4 5
So if you wanted "Y", you could just type
"PYTHON"[1] (always start counting from 0!)
"""
fifth_letter = "MONTY"[4]
print fifth_letter
#23
parrot = "Norwegian Blue"
print len(parrot)
#24
parrot = "Norwegian Blue"
print parrot.lower()
#25
parrot = "norwegian blue"
print parrot.upper()
#26
"""Declare and assign your variable on line 4,
then call your method on line 5!"""
pi=3.14
print str(pi)
#27
ministry = "The Ministry of Silly Walks"
print len(ministry)
print ministry.upper()
#28
"""Tell Python to print "Monty Python"
to the console on line 4!"""
print "Monty Python"
#29
"""Assign the string "Ping!" to
the variable the_machine_goes on
line 5, then print it out on line 6!"""
the_machine_goes = "Ping!"
print the_machine_goes
#30
# Print the concatenation of "Spam and eggs" on line 3!
print "Spam "+"and "+"eggs"
#31
# Turn 3.14 into a string on line 3!
print "The value of pi is around " + str(3.14)
#32
string_1 = "Camelot"
string_2 = "place"
print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)
#33
name = raw_input("What is your name?")
quest = raw_input("What is your quest?")
color = raw_input("What is your favorite color?")
print "Ah, so your name is %s, your quest is %s, " \
"and your favorite color is %s." % (name, quest, color)
#34
# Write your code below, starting on line 3!
my_string ="haha"
print len(my_string)
print my_string.upper()
#35