»» NOTES ««
- .ipynb (Interaction Python Notebook)
- code cell = box where user can choose language of program, and subsequently create runnable code. (Not interactive on Website)
- code fencing = Used to mark the start and end of code block (typically starts and ends with, “```”)
- Psuedo code = simple text language that can be substituted for any real coding language.
- Sequenece: A set of steps carried out in a defind order
- Iteration: repeats a block of code in certain order throguht the use of a function.(Definite Iteration and Indefinite iteration)
- To apply any changes you make inside of .ipynb you must:
- Select what type of text you want to add(Markdown, Python, HTML, Javascipt, etc…) Found in bottom right corner of code cell.
- (1) Run “make clean”
- (2) Run “make”
»» CODE FENCING VS CODE CELL ««
»» CODE FENCING ««
print("This is an example of using code fencing)
My code doesn't need to follow any sytax or rules here!
I also can't run the code I put into this cell
»» CODE CELL ««
print("This is an example of a code cell")
print("Here My code must follow the rules of whatever language I choose")
fact = "My code here is runnable!"
print(fact)
This is an example of a code cell
Here My code must follow the rules of whatever language I choose
My code here is runnable!
Command Vocabulary | Pseudo code | Python | Purpose |
Output | DISPLAY(expression) | print(expression, end=” “) | Displays the value of expression, followed by a space. Python defaults to newline, thus the end=” “ |
Input | a ← INPUT() | a = input(prompt) | Accepts a value from the user and returns it to the variable a. |
Assignment | a ← expression | a = expression | Evaluates expression and assigns the result to the variable a. |
Selection | IF (expression) | if expression: | Run commands in the code block associated with the selection |
Iteration n times | REPEAT n TIMES | for i in range(n): | Repeat commands in the code block associated withe the iteration n times |
Iteration expression | REPEAT UNTIL (expression) | while expression: | Repeat commands in the code block associated withe the iteration while expression is true |
List Assignment | list ← [expression1, expression2, expression3] | list = [expression1, expression2, expression3] | Assigns 3 values to list, value can be literal or expressions |
First index in List | list[1] | list[0] | Access the 1st element in the list[]. FYI, most programming languages start a zero. |
Last index in List | list[LENGTH(list)] | list[len(list) - 1] | Access the last element in the list[]. If you start at zero, last element is length - 1. |
Define Procedure | PROCEDURE name (parameter) | def name(parameter): | Create a procedure containing a sequence of programming instructions. |
Expression equals | a = b | a == b | Evaluate if assigned value of a equals assigned value of b |
Expression not equals | a ≠ b | a != b | Evaluate if assigned value of a is NOT equal to assigned value of b |
»» PSUEDO VS PYTHON VS JAVASCRIPT ««
»» Psuedo ««
DISPLAY("Psuedo Code Example")
n ← INPUT("How many times should this code run?")
total ← 0
sum ← 0
REPEAT n TIMES
{
DISPLAY("This is run, # "+n)
total +1
sum ← sum + n
}
DISPLAY("In toal this code has been run "+total+ " times and the sum of the numbers is: "+sum)
IF (sum > 100) {
DISPLAY("Your sum of nubmers was greater than 100!")
}
ELSE {
DISPLAY("Your sum of nubmers was not greater than 100!")
}
»» Python ««
print("Python Example")
n = int(input("How many times should this code run?"))
total = 0
sum=0
for i in range(n):
print("This is run, # "+str(i))
total+=1
sum=sum+i
print("In toal this code has been run "+str(total)+ " times and the sum of the numbers is: "+str(sum))
if (sum>100):
print("Your sum of numbers was greated than 100")
else:
print("Your sum of numbers is not past 100")
Python Example
This is run, # 0
This is run, # 1
This is run, # 2
This is run, # 3
This is run, # 4
This is run, # 5
In toal this code has been run 6 times and the sum of the numbers is: 15
Your sum of numbers is not past 100
»» Javascript ««
// JAVASCRIPT EXAMPLE HERE
%%js%%
File "/tmp/ipykernel_243079/141280344.py", line 1
// JAVASCRIPT EXAMPLE HERE
^
SyntaxError: invalid syntax
»» Final Thoughts ««
As of the current moment, Python is the fastest code to use, Pseudo is the easiest to understand, and Javascript is the hardest to work on. Need to figure out how to create a for loop in Javascript.