Pseudocode!

If statements

This is a pseudocode example of using if statements on their own. We’ll go further into else statements after this.

boolean = false;
int = 17;
string = ‘bob’

if boolean is true
    display “Variable is true!”
// This will not display any value since boolean is set to false

if int >= 10
    display “This number is greater than or equal to 10!”
// This will display the value due to the fact the int is equal to 17

if string == 'bob'
    display "String is equal to bob"
// This will display the value since the string's are the same, if they weren't it would not

Else Statements

A pseudocode example of how to use else statemnets and there purpose.

boolean = false;
int = 17;
string = ‘bob’

if boolean is true
    display 'boolean is true!'
else
    display 'boolean is false!'
// Due to the boolean being false the if statement will not work, thus not displaying "boolean is true!" When the if statement fails the else statement runs no matter what.

if int >= 10
    display 'This number is greater than or equal to 10!'
else
    display 'This number is less than 10'
// The above code will display 'This number is greater than or equal to 10!'. It will not display 'This number is less than 10' due to the fact that it already meets the qualifications for the first if statement. Therefore it stops going through the if statement, and does no go to the else statement.

Nesting Conditionals

This is a pseudocode example of how to nest conditionals.

boolean = false;
int = 17;

if boolean == true
    if int >= 10
        display 'This is both true and greater than or equal to 10'
    else
        display 'This is both true and less than 10'
else
    if int >- 10
        display 'This is both false and greater than or equal to 10'
    else
        display 'This is both false and less than 10'
// The display will read 'This is both false and greater than or equal to 10.' This is due to the fact that we have an if statement in another if statement. In this code it runs through the first if statement, and then runs the second if statement. This second if statement runs display 'This is both true and greater than or equal to 10'. The first if statement checks false and moves to the else statement. Then the if statement is checked, and since it is true displays 'This is both false and greater than or equal to 10'.

Hack 1

Your hack is to create a piece of code that compares two statements and checks if they are equal to each other

Hack 2

Create a hack that compares two variables to one another, if they are true return “We are the same” if they are not check if they are the same length, if they are return “We are the same length!” If none of these are true return “We are not that similar :(”

Hint: Use the len() function. len() function accepts a string as an input and outputs the string’s length

Hack 3

Create a hack that asks the user to type the numbers up to 10. Not all at once.