Unit 3 Vocabulary Terms

  • Variables
    • Data Types - a classification that specifies which type of value a variable has
    • Assignment Operators - he operator used to assign a new value to a variable, property, event or indexer element in C# programming language
age = 15
name = "Soham"
  • Managing Complexity with Variables
    • Lists - any information displayed or organized in a logical or linear formation
    • 2D Lists - list of lists
    • Dictionaries - an abstract data type that defines an unordered collection of data as a set of key-value pairs
    • Class - a template definition of the method s and variable s in a particular kind of object
animals = ["dogs","cat"]
  • Algorithms
    • Sequence - the first programming construct
    • Selection - a programming construct where a section of code is run only if a condition is met
    • Iteration - a process where the design of a product or application is improved by repeated review and testing
def isPalindrome(s):
    return s == s[::-1]
 
 
# Driver code
s = "malayalam"
ans = isPalindrome(s)
 
if ans:
    print("Yes")
else:
    print("No")
Yes
  • Expressions
    • Comparison Operators - operators that compare values and return true or false
    • Truth Tables - A truth table is a way of summarising and checking the logic of a circuit. The table shows all possible combinations of inputs and, for each combination, the output that the circuit will produce.
print(5>2)
True
  • Characters - a display unit of information equivalent to one alphabetic letter or symbo (char)
string = "Hello, world!"
characters = list(string)
print(characters)
['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!']
  • Strings - A string is generally considered a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding.
info = 15
print(str(info))
15
  • Length - length of a string
info = "fiwhasnoguhebiudsnoidkj"
print(len(info))
23
  • Concatenation - combining 2 or more strings
string1 = "Hello"
string2 = "world"
concatenated_string = string1 + " " + string2
print(concatenated_string)
Hello world
  • Upper - converts the string to uppercase
info = "OIJHUHYBNJJIHUfoeiajnjieofoJIPOUBYUV"
print(info.upper())
OIJHUHYBNJJIHUFOEIAJNJIEOFOJIPOUBYUV
  • Lower - converts the string to lowercase
info = "OIJHUHYBNJJIHUfoeiajnjieofoJIPOUBYUV"
print(info.lower())
oijhuhybnjjihufoeiajnjieofojipoubyuv
  • Traversing Strings - accessing all the elements of the string one after the other by using the subscript
string = "Hello, world!"
for character in string:
  print(character)
H
e
l
l
o
,
 
w
o
r
l
d
!
  • Python If - a statement with an if condition
if 6<9:
    print("no")
  • Elif - when the if condition is not met, it comes here. Used when you want to add multiple other conditions
elif 5>4:
    print("maybe")
  • Else conditionals - when the if condition is not met, it comes here.
else:
    print("yes")
  • Nested Selection Statements - selection statements that are nested within themselves
x = 10
y = 20

if x > 5:
  if y > 15:
    print("x is greater than 5 and y is greater than 15")
  else:
    print("x is greater than 5 but y is not greater than 15")
else:
  print("x is not greater than 5")
x is greater than 5 and y is greater than 15
  • Python For - a condition that repeats multiple times
for i in range(0,6):
    print(i,"cookies")
0 cookies
1 cookies
2 cookies
3 cookies
4 cookies
5 cookies
  • While loops with Range - while loop that uses the range() function
i = 5
while i in range(0,6):
    print(i,"cookies")
    i = i - 1
5 cookies
4 cookies
3 cookies
2 cookies
1 cookies
0 cookies
  • with List - Lists are used to store multiple items in a single variable.
numbers = [1, 2, 3, 4, 5]

for index, number in enumerate(numbers):
  print(f"Number at index {index}: {number}")
Number at index 0: 1
Number at index 1: 2
Number at index 2: 3
Number at index 3: 4
Number at index 4: 5
  • Combining loops with conditionals to Break, Continue - For certain conditions, the loop will terminate exectution
for i in range(10):
    if i % 2 == 0:
        continue
    print(i)

# Output: 1 3 5 7 9
1
3
5
7
9
  • Procedural Abstraction - when we write code sections (called "procedures" or in Java, "static methods") which are generalised by having variable parameters.
def calculate_tax(price, tax_rate):
  tax = price * tax_rate
  total = price + tax
  return total

print(calculate_tax(100, 0.1))  # Output: 110.0
110.0
  • Python Def procedures - A procedure allows us to group a block of code under a name, known as a procedure name
def addition(x):
    x = x + 5
    return x

addition(5)
10
  • Parameters - values that are passed through a function
def greet(name):
  print(f"Hello, {name}!")

greet("John")  # Output: "Hello, John!"
Hello, John!
  • Return Values - a value that a function returns to the calling script or function when it completes its task
def add(x, y):
  result = x + y
  return result

print(add(10, 20))  # Output: 30
30