if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Octal | Binary | File Mode |
---|---|---|
0 | 000 | --- |
1 | 001 | --x |
2 | 010 | -w- |
3 | 011 | -wx |
4 | 100 | r-- |
5 | 101 | r-x |
6 | 110 | rw- |
7 | 111 | rwx |
Ex. "chmod 600 foo.txt" sets the mode -rw------- to the file
The most common octals are: 7, 6, 5, 4, and 0
./firefox
print('you are too old!')
this is block 1
this is block 1
this is block 2
this is block 2
this is block 2
this is block 3
this is block 3
this is block 2
this is block 1
this is block 1
>>> age = 18
>>> if age == 12:
. . . print('Hello')
. . . else:
. . . print('Goodbye')
>>> pets = 2
>>> if pets == 1:
. . . print("You have 1 pet")
. . . elif pets == 2:
. . . print("You have 2 pets")
. . . elif age < 13:
. . . print("You have less than 3 pets")
. . . else:
. . . print("You have more than 2 pets")
What will be printed?
>>> if age ==10 or age == 11 or age ==12:
. . . print("You are %s" % age)
>>> if age >= 10 and age <= 12:
. . . print("You are %s" % age)
for variable in list:
The variable iterates through the list and is assigned the value of the current iteration
for x in range(5):
y = x + 1
print(x+y)
for s in myList:
print(s)
>>> savings = 0
>>> for week in range(1, 53):
... savings = savings + 35
... print("Week %s = $%s" % (week, savings))
>>> myList = ['a', 'b', 'c']
>>> for u in myList:
... print(u)
... for v in myList:
... print(v)
If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?
while condition:
# block of code
x = 1
while x < 200:
x = 2*x
print(x)
What will this print?
Answer the previous question using a while loop
If you don't remember the task:
If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?
def function(parameter):
# block of code
You define (make) the function like this:
def printName(name):
print("Hello, %s!" % name)
And call (use) it like this:
printName("John")
Which will print:
Hello, John!
Another example, except with return instead of print():
def savings(chores, job, spending):
return chores + job - spending
# or return(chores+job-spending)
And call it like this:
print(savings(10, 10, 5))
# OR
money = savings(10, 10, 5)
# This is a global variable
a = 0
if a == 0:
# This is still a global variable
b = 1
def my_function(c):
# this is a local variable
d = 3
print(c)
print(d)
# Now we call the function, passing the value 7
# as the first and only parameter
my_function(7)
# a and b still exist
print(a)
print(b)
# c and d don't exist anymore -- these statements
# will give us name errors!
print(c)
print(d)