This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # print a string | |
| print "Mary had a little lamb." | |
| # print a string that has formatting characters in it | |
| print "Its fleece was white as %s." % 'snow' | |
| # print a string | |
| print "And everywhere that Mary went." | |
| # print a string and print it 10 times |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #assign a String to the variable x. The String is a formatted String | |
| #where we replace %d with 10 | |
| x = "There are %d types of people." % 10 | |
| #assign the variable 'binary' with a value which is a String 'binary' | |
| binary = "binary" | |
| #assign a String to the variable do_not | |
| do_not = "don't" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #assign a String to the variable x. The String is a formatted String | |
| #where we replace %d with 10 | |
| x = "There are %d types of people." % 10 | |
| #assign the variable 'binary' with a value which is a String 'binary' | |
| binary = "binary" | |
| # | |
| do_not = "don't" | |
| y = "Those who know %s and those who %s." % (binary, do_not) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kg_to_pound = 2.20462262185 | |
| inch_to_cm = 2.54 | |
| name = 'Zed A. Shaw' | |
| age = 35 # not a lie | |
| height = 74 # inches | |
| height_in_cm = height * inch_to_cm | |
| weight = 180 # lbs | |
| weight_in_kg = weight/kg_to_pound | |
| eyes = 'Blue' | |
| teeth = 'White' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = 'Zed A. Shaw' | |
| age = 35 # not a lie | |
| height = 74 # inches | |
| weight = 180 # lbs | |
| eyes = 'Blue' | |
| teeth = 'White' | |
| hair = 'Brown' | |
| print "Let's talk about %s." % name | |
| print "He's %d inches tall." % height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my_name = 'Zed A. Shaw' | |
| my_age = 35 # not a lie | |
| my_height = 74 # inches | |
| my_weight = 180 # lbs | |
| my_eyes = 'Blue' | |
| my_teeth = 'White' | |
| my_hair = 'Brown' | |
| print "Let's talk about %s." % my_name | |
| print "He's %d inches tall." % my_height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Define a variable called cars and give it the integer value 100 | |
| cars = 100 | |
| #Define a variable called space_in_a_car a nd give it the floating point value 4.0 | |
| space_in_a_car = 4.0 | |
| #Define a variable called drivers, and give it the integer value 30 | |
| drivers = 30 | |
| #Define a variable called passengers, and give it the integer value 90 | |
| passengers = 90 | |
| #Define a variable called cars_not_driven, and compute it as the difference between cars and drivers | |
| cars_not_driven = cars - drivers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #THIS CODE HAS AN ERROR | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The meaning of operators in Python | |
| # + plus Addition | |
| # - minus Subtraction | |
| # / slash Division | |
| # * asterisk Multiplication | |
| # / percent Also modulus operator, which returns the remainder from division | |
| # < less-than Returns true if the operans on the LHS is less than RHS | |
| # > greater-than Returns true if the operand on the LHS is greater than RHS | |
| # <= less-than-equal Returns true if the operand on the LHS is less than or equal to RHS | |
| # >= greater-than-equal Returns true if the operand on the LHS is greater than or equal to the RHS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A comment, this is so you can read your program later. | |
| # Anything after the # is ignored by Python. | |
| 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 won't run." | |
| print "This will run." |