Stupid way to learn Python (exercise1-15)

Source: Internet
Author: User

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
Carpool_capacity=cars_driven*space_in_ A_car
Print "We need to put", average_passengers_per_ Car, "in each car."
#exercise5 standard text format, variables nested inside text
my_name= ' Caijiangyao '
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

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*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 First 2nd 3rd

#exercise14 parameters, unzip, variable
From sys import ARGV, ZED=ARGV
prompt = ' > '
Print "

#exercise15 Read the file
From sys import ARGV
Txt=open (filename)
Print "Here ' s your file%r:"%filename
Print ()

print "Type the filename again:"
File_again=raw_input (">")
Txt_again=open (File_again)
Print ()

Stupid way to learn Python (exercise1-15)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.