George Boole defined a branch of math that we use today in the Python programming language. Boolean math seeks to answer things as True or False. This is helpful to us because computers only recognize 0s and 1s. To program it is helpful to try and think like a computer. Python refers to Boolean values in as those defined by either being true, or false, but never maybe. Example: myBool=5 >6 ;myBool will return false.
Using the if-then-else and if-then structures allows us to set up a parameter for our program to process information and make a decision for us. Right now I keep checking the clock because if its 3:00 I will go to work. If it is not 3:00 I will continue to work. This is the type of decision we could build a program to make for us. This would involve a loop to continuously recheck the time.
A simpler version of an if-then structure would be to ask a question to someone using your program.
myFav = int(input(“Try to guess my favorite number. Hint! It is less than 10.”))
if (myFav == 7):
print(“You guessed my favorite number!”)
This type of program can become far more complex. If I wanted to have someone guess my favorite number between 1 and 1000 I could have the program ask them to guess. If they were right, let them know. If they were wrong I could have a program tell them that the number is higher or lower than what they guessed and let them guess again. Eventually the program would complete when they got it right.
Respond 150 words Minimum
Boolean is a data type that expresses true or false (0 or 1) decisions (Pazos, 2016). This data type can be used to see if variables are equal to, greater than, or less than. Boolean can only be equal to true or false, meaning you can’t tie a string text or integers to this express (Pazos, 2016). Under Boolean you can choose whichever variable you want however it can only have two results, true or false. Within python you could type “true == true” and the program responds “true”. You could also type “1 ==2” and the response would be false. There are endless possibilities to ask the program if the variables are true or not. Another option is to add, subtract, and combine the true and false results by stating AND, OR, and NOT (Pazos, 2016). Within the program however they must be replaced by &&, II, and ! respectfully. For example, type “not (1 != 10 or 3 == 4)” and the results would be false. This statement is stating that the following line is false (1 is not equal to 10 and 3 is equal to 4) and the response from the program is false. The response is false because the actual statement is true but you declared false with the “not”, which the program disagrees with.
If-then structures outline to a program that “if” a certain value is met “then” perform a certain execution. In other words, it’s a code that tells the program what to do when a specific condition is true. This condition could be either true or false, meaning the execution code can be a trigger for either event depending on the user’s expectations. If you wanted the program to executed an action for if the condition was met and another action if not met this is where the “else” statement is used. The else statements execute coding when the condition is false or “0”.