码迷,mamicode.com
首页 > 编程语言 > 详细

Codecademy python

时间:2015-02-13 19:55:24      阅读:639      评论:0      收藏:0      [点我收藏+]

标签:

#1

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

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

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

 

Codecademy python

标签:

原文地址:http://www.cnblogs.com/qscqesze/p/4290814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!