Notes from 3.5-3.7

3.5 Important vocab

  • Boolean
  • Relational Operator
  • Logical Operator

Boolean Operators: Produces booleans after used between 2 values

Relational Operators: These can work between any 2 values of the same type known as operands

Logical Operators: These are operators that works on operand(s) to produce a single boolean result

3.6 Algorithm - set of instructions that accomplish a certain task Selection - the process that determines which parts of an algoritm is being executed based on a condition Conditional - a statement that affects the outcome of a program by executing different statements based on the result of a true or false statement (boolean)

Examples of conditionals are if else statements

3.7 Nested Conditional statements - conditional statements within conditional statements

Homework/Hacks

our homework we have decided for a decimal number to binary converter. You must use conditional statements within your code and have a input box for where the decimal number will go. This will give you a 2.7 out of 3 and you may add anything else to the code to get above a 2.7.

Below is an example of decimal number to binary converter which you can use as a starting template.

def DecimalToBinary(num):
    strs = ""
    while num:
        if (num & 1):
            strs += "1"
        else:
            strs += "0"
        num >>= 1
    return strs
 
def reverse(strs):
    print(strs[::-1])
 
num = 67
print("Binary of num 67 is:", end=" ")
reverse(DecimalToBinary(num))
Binary of num 67 is: 1000011
def DecimalToBinary(num):
    decimal = 24
    if num >= 1:
        DecimalToBinary(num // 2)
    print(num % 2, end = '')
if __name__ == '__main__':
    decimal = 24
    DecimalToBinary(decimal)
011000

Frontend Version using html and javascript (click "view on github" to see actual code w comments)

Type a decimal number and press tab to convert to binary:

Binary :