Algorithms
Operations
Subtraction: Represented by “-"
Addition: Represented by "+"
Multiplication: Represented by “*”
Division: Represented by “/”
Getting the Remainder: Represented by “MOD” (% in python)
Order of Operations
Arithmetic operations in programming are performed in the same order as operations in mathematics:
Operations in parentheses should be done first.
Division and multiplication should be done before addition and subtraction.
Modulus works similar to multiplication and division.
Example: Evaluate num1
5 % 2
num1 = 9 % 2 * ( 8 - 2 ) + 8 / ( 6 - 4 )
print(num1)
var1 = 9
var2 = 7
var3 = 2
#var = var1 + 5
#var2 = var1 - var3
#var1 = var2
#var3 = (var1 + var2) / 2
#var2 = 6
print(var1)
print(var2)
print(var3)
Strings
What is a String?
A String: A string is a collection of characters. What is a character as character can be anything from numbers, letters, spaces, special symbols, etc.
A string is a collection of characters. What is a character as character can be anything from numbers, letters, spaces, special symbols, etc.
Certain procedures may be used with strings and they vary from programming language to language Python examples
len() to find the length of a string
lower() to convert to lowercase
etc. Pseudocode examples
len() returns the length of a string
concat() returns a string made up of the concatenated strings ex. concat("string1", "string2") would return string1string2
substring() returns the characters from the string beginning at the at the first position to the last so an example of this would be substring ("abcdefghijk", 2, 5) would print bcde (pseudocode starts at 1)
String Concatenation
What is string concatenation?
String concatenation is combining 2 or more strings to make a new strings in order to create a new string
concat() in pseudocode and varys from language to language can be used to combine to strings such as concat("cookie","monster") returns cookiemonster
Substrings
What is a substring?
A substring is a part of and already existing string.
In pseudocode substring() method is used for instance for concat("Mr.Mortenson is very handsome" 1, 2) the system would return Mr (remember that pseudocode starts at 1)
Num1 = 50
Num2 = Num1 % 9 + 15
Num3 = Num2 / Num1 + ( Num2 * 2 )
Num4 = Num3 + Num1 / 5 - 10
Result = Num4 - Num2
# Num2 = 5+15 = 20
# Num3 = 20/50 + (20*2)= 40.4
# Num4 = 40.4 + 50/5 -10 = 40.4
# Result = 40.4 - 20 = 20.4
print(Result)
Num1 = 10
Num2 = Num1 % 3 * 4
Num1 = Num2
Num3 = Num1 * 3
Result = Num3 % 2
# Num2 = 1 * 4 = 4
# Num1 = 4
# Num3 = 4 * 3 = 12
# Result = 12 % 2 = 0
print(Result)
valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA
valueA = valueA * 10
if valueB > 10:
print(valueC)
type = "curly"
color = "brown"
length = "short"
type = "straight"
hair = type + color + length
print(hair)