# Trying to learn python using Learn Python the Hard Way by Zed Shaw # Combining several exercises in one go # Ex1.py print "Hello World!" print "Hello Again" print "I like typing this." print "This is fun" print 'Yay! Printing.' print "I'd much rather you 'not'." print 'I "said" do not touch this.' # printing one line print "" # Ex2.py # removed the other comments print "I could have code like this." #and the comment after is ignored # You can also use a comment to "disable" or comment out a piece of code: # print "This will run" print "This will run." print "" # ex3 print "I will now count my chickens:" print "" print "Hens", 25 + 30 / 6 print "Roosters", 100 - 25 * 3 % 4 print "" print "Now I will count the eggs:", 3 + 2 + 1 - 5 + 4 % 2 -1 /4 + 6 #I like it to be right beside the sentence print "" print "Is it true that 3 + 2 < 5 -7?" print 3 + 2 < 5 - 7 print "What is 3 + 2?", 3 + 2 print "What is 5 - 7?", 5 - 7 print "Oh,that's why it's False." print "How about some more." print "Is it greater?", 5 > -2 print "Is it greater or equal?", 5 >= -2 print "Is it less or equal?", 5 <= -2 print "" #Ex4 cars = 100 space_in_car = 4.0 drivers = 30 passengers = 90 cars_not_driven = cars - drivers cars_driven = drivers carpool_capacity = cars_driven * space_in_car average_passengers_per_car = passengers / cars_driven print "There are", cars,"cars available." print "There are only", drivers, "drivers available." print "There will be", cars_not_driven, "empty cars today." print "We can transport", carpool_capacity, "people today." print "We have", passengers, "to carpool today." print "We need to put about", average_passengers_per_car, "in each car." #Ex5 my_name = 'JD' my_age = 33 my_height = 64.5 # "5'4\"" <-if using string, escape sequence example my_weight = 135 #lbs my_eyes = 'Black' my_teeth = 'White' my_hair = 'Black' print "Let's talk about %s." % my_name #string substitution print "He's height is %r." % my_height print "He's %d pounds heavy." % my_weight print "Actually that's not too heavy." print "He's got %s eyes and %s hair." % (my_eyes, my_hair) print "His teeth are
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question