Learn Python the Hard Way

來源:互聯網
上載者:User

標籤:

ex1.py

1 print "Hello World!"2 print "Hello Qiwei"3 print "I like typing this."4 print "This is fun."5 print ‘Yay! Printing.‘6 print "I‘d much rather you ‘not‘."7 print ‘I "said" do not touch this.‘

 

 

ex2.py  Comments and Pound Characters

1 #A comment, this is so you can read your program later.2 #Anything after the # is ignored by python.3 4 print "I could have code like this." #and the comment after is ignored5 6 #You can also use a comment to "disable" or comment out a piece of code;7 #print "This won‘t run."8 9 print "This will run."

 

 

ex3.py Numbers and Math

 1 print "I will now count my chickens:" 2  3 print "Hens", 25 + 30 /6 4 print "Roosters", 100 - 25 * 3 %4 5  6 print "Now I will count the eggs:" 7  8 print 3 + 2 + 1 -5 + 4 % 2 - 1 / 4 + 6 9 10 print "Is it true that 3 + 2 < 5 - 7?"11 12 print 3 + 2 < 5 - 713 14 print "What is 3 + 2?", 3 + 215 print "What is 5 - 7?", 5 - 716 17 print "Oh, that‘s why it‘s False."18 19 print "How about some more."20 21 print "Is it greater?", 5 > -222 print "Is it greater or equal", 5 >= -223 print "Is it less or equal?", 5 <= -2

 

 

ex4.py Variables And Names

 1 cars = 100 2 space_in_a_car = 4.0 3 drivers = 30 4 passengers = 90 5 cars_not_driven = cars - drivers 6 cars_driven = drivers 7 carpool_capacity = cars_driven * space_in_a_car 8 average_passengers_per_car = passengers / cars_driven 9 10 print "There are", cars, "cars available."11 print "There are only", drivers, "drivers available"12 print "There will be", cars_not_driven, "empty cars today."13 print "We can transprot", carpool_capacity, "people today."14 print "We have", passengers, "to carpool today."15 print "We need to put about", average_passengers_per_car, "in each car."

 

 

 

  

 

Learn Python the Hard Way

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.