#exercise1
Print "Hello world!"
Print "Hello Again"
Print "I like typing this."
Print "This was fun."
print ' yay! Printing. '
Print "I ' d much rather you ' not '."
print ' I ' said ' do not touch this. '
#exercise2 #号的用处
#exercise3 numeric and mathematical calculations
print "Hen", 25+30/6
Print "Hen", Round (25+30/6,1) #round函数返回浮点型数据
Print section
print "Roosters", 25*3%4 #先乘法后求模
Print 3+2<5-7
print "Is it Greater ", 5>-2
#exercise4 variable
cars=100
space_in_a_car=4.0
drivers=30
passengers=90
cars_not_driven=cars-drivers
cars_driven=drivers
Carpool_capacity=cars_driven*space_in_ A_car
Average_passengers_per_car=passengers/cars_driven
Print "We need to put", average_passengers_per_ Car, "in each car."
#exercise5 standard text format, variables nested inside text
my_name= ' Caijiangyao '
my_age=24
my_height=43
My_ weigh=45
my_eye= ' black '
my_teeth= ' white '
my_hair= ' Brown '
Print "Let's talk about%s."% my_name #变量为字符串时要用%s
Print "She is%d. inches tall."%my_height #变量为数值时要用%d
Print "She ' s got%s eyes and%s hair"% (my_eye,my_teeth) #多个变量嵌套时
Print "If I add%d,%d and%d I get%d."% (My_age,my_height,my_weigh,my_age+my_height+my_weigh)
Print "My height%d"% my_height
#exercise6 string and text
X= "There is%d types of people."%10
binary= "Binary"
do_not= "Don ' t"
Y= "Those who know%s and those who%s."% (Binary,do_not)
Print X
Print Y
Print "I said:%r."%x #r引用简写的变量名x
Print "I also said: '%s '"%y #引用简写的变量名y
Print "I also said:%r"%y
Hilarious=false
joke_evalution= "isn ' t that joke so funny?! %r
Print Joke_evalution%hilarious
W= "This was the left side of ..."
E= "A string with a right side."
Print W+e
#exercise7 More Printing
Print "Mary had a little lamp."
Print "Its fleece is white as%s"% ' snow '
Print "and everywhere that Mary went."
Print "." *10 #文本字符串与数字乘 10 of .....
End1= "C"
End2= "H"
End3= "E"
End4= "E"
End5= "S"
End6= "E"
End7= "B"
end8= "U"
End9= "R"
End10= "G"
End11= "E"
End12= "R"
Print End1+end2+end3+end4+end5+end6,
Print End7+end8+end9+end10+end11+end12 #, which makes two print records linked together
#exercise8 Printing
The difference between printing "%r" and "%s" is that "%r" is good for debugging because it shows the raw data of the variable, while the other symbols are used to show the output to the user.
Formatter= "%r%r%r%r"
Print formatter% (1,2,3,4)
Print Formatter% ("one", "one", "one", "three", "four")
Print Formatter% (
"I had this ting",
"That's could type up right.",
"But it didn ' t sing.",
"So I said Goodnight.")
#exercise9 print, print, print
days= "Mon Tue Wed Thu Fri Sat Sun"
Months= "Jan\nfeb\nmar\napr\nmay\njun"
Print "Here are the days:"
Print "Here is the months:", months
Print "" "There ' s someting going on here.
With three double-quotes.
Even 4 lines if we want, or 5, or 6.
"""
#exercise10 what is that?
Print "I am 6 ' 2\" tall. "
print ' I am 6\ ' 2 "tall. ' #在容易混杂的符号前加上反斜杠 \ (back slash)
tabby_cat= "\ti ' m tabbled in."
Print Tabby_cat
persian_cat= "I ' m split\non a line." #\n line break
Print Persian_cat
blackslach_cat= "I ' m\\ a\\cat."
Print Blackslach_cat #另一个 \ is in the original
Fat_cat= "" "
I ' ll do a list:
\t*catfood
\t*catnip\n\t* Grass
"""
Print Fat_cat
#exercise11 questions
Print "How is old is you?",
Age=raw_input ()
Print "How tall is You?",
Height =raw_input ()
Print "How much does you weight?",
Weight =raw_input ()
Print "So" is%r old,%r tall,and%r heavy. "% (age,height,weight)
#exercise12 prompting others
Y=raw_input ("Name?") #这句话会用 "Name" prompts the user and assigns the result of the user input to the variable Y.
#这就是我们提问用户并且得到答案的方式.
Age=raw_input ("How old is You?")
Height=raw_input ("How Tall is You?")
Weight=raw_input ("How much does you weigh?")
Print "So" is%r old,%r tall,and%r heavy. "% (age,height,weight)
#exercise13 parameters, unzip, variable
From sys import ARGV
Script, first, second, third = argv
Print "The script is called:", script
Print "Your first variable is:", first
Print "Your second variable is:", second
Print "Your third variable is:", third
Python ex13.py First 2nd 3rd
#exercise14 parameters, unzip, variable
From sys import ARGV
ex1.py, ZED=ARGV
prompt = ' > '
Print "
#exercise15 Read the file
From sys import ARGV
script,filename=argv
Txt=open (filename)
Print "Here ' s your file%r:"%filename
Print Txt.read ()
print "Type the filename again:"
Ex15_sample
File_again=raw_input (">")
Txt_again=open (File_again)
Print Txt_again.read ()
Stupid way to learn Python (exercise1-15)