This file contains 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
#!/usr/bin/env python | |
# Selection sort. | |
i = 0 | |
while i < len(a): | |
p = i | |
j = i + 1 | |
while j < len(a): | |
if a[j] < a[p]: | |
p = j |
This file contains 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 area of the pitch at Old Trafford | |
length = 105 | |
width = 68 | |
area = length * width | |
# area # 7140 |
This file contains 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
tmp = a | |
a = b | |
b = tmp |
This file contains 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
#!/usr/bin/env python | |
print "Hello, World!" |
This file contains 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
#!/usr/bin/env python | |
# Assume an existing integer variable n | |
# Write an assignment statement which doubles the value of n | |
n = 2 * n |
This file contains 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
# Current Working Directory | |
# An active terminal is always associated with a particular directory known as the current working directory (CWD). | |
# pwd: prints the CWD name to the terminal | |
# cd: changes the CWD | |
# ls: lists the files and directories contained in the CWD | |
cd # Change the CWD to your home directory | |
cd ~ # Change the CWD to your home directory (alternative) | |
cd ~/Desktop # Change the CWD to your desktop directory | |
cd .. # Change the CWD to the parent of the CWD | |
ls # List the contents of the CWD |
This file contains 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
#!/usr/bin/env python | |
n = input() # Read the integer from standard input. | |
print n * n # Write n squared to standard output. |
This file contains 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
#!usr/bin/env python | |
s = raw_input() # It's text, so use raw_input() instead of input(). | |
print len(s) # Write the length to standard output. |
This file contains 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
#!/usr/bin/env python | |
age = input() # 1. It's an integer. 2. It's an age. | |
print 12 < age and age < 20 |
This file contains 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
x = input() # The length of the base of a rectangle. | |
y = input() # The height of the rectangle. | |
if x == y: | |
print "square" | |
else: | |
print "rectangle" |
OlderNewer