hypothes.is tag: s20iostpy05ualr Conditional operators, also known as relational operators, are used to compare the relationship between two operands. Expressions that can only result in one of two answers are known as Boolean expression. c. <= _____________ __
d. >= ________________ e. != _____________ __ f. ==
________________ x = 4, y = 5, z = 4 3. What is the result of the following expressions given the following variable assignments? word1 = "hello", word2 = "good-bye" 4. Explain how the conditional operators are used when the operands are strings. 5. What are the only two possible answers to all of the expressions in questions 2 and 3? Model 2: Programming Structures6. Each of the flowchart symbols in the chart above represents lines or segments of code. After examining the chart, write a description of: a. sequence structure 7. Which structure best describes the types of Python programs you have written so far? Do you think this structure is the best structure to use for all programs? Why or why not? 8. Which structure allows the programmer to create code that decides what code is executed? Model 3: IF/ELSE Statement
9. Consider Model 3 above: a. What is the Python code equivalent of the diamond flowchart symbol in the program above? b. What is the output of the program? c. What would the output of the program be if the value of the variable examScore was set to 85? 10. Execute the two following python programs by copying and pasting into your editor window of Thonny IDE.
Note We can use logical operators to determine logic between conditions (relational expressions). 12. Sometimes you want to include more than one condition to determine which code segment is executed. You can use the following logical operators to create compound conditions. Examine each operator and a sample of its use and provide an explanation of how the operator works.
numCredits = int(input("Enter number of credits: ")) majorGPA = float(input("Enter GPA for the major: ")) overallGPA = float(input("Enter overall GPA: ")) if ________: print("congratulations?") print("You seem to meet all the criteria for graduation.") else: print("Sorry") print("You do not meet all the criteria for graduation/") print("Done!") The Missing Boolean expression is(?) a. numCredits >= 120 or majorGPA >= 2.0 or overallGPA >= 2.0 b. numCredits > 120 and majorGPA > 2.0 or overallGPA > 2.0 c. numCredits > 119 and majorGPA >= 2.0 and overallGPA >= 2.0 d. numCredits >= 120 and majorGPA >= 2.0 and overallGPA >= 2.0 15. Enter and execute the program in #14. Include your choice for the correct Boolean expression and create several sets of data to test all possibilities for the Boolean expression. List the data you used to test all possibilities for the expression and explain your choices.
Group Application Questions: Use the Thonny IDE to check your work
2. Write a python program that sets a variable called isValid to a Boolean value. Then create an if statement that prints a
random number between one and six. If the value stored in the variable isValid equals the Boolean value print true, otherwise print false. 3. Write the code for an if statement that adds 5 to the variable num1 if the value stored in the variable testA equals 25.
Otherwise subtract 5 from num1. 4. Write a Python program that prompts the user for a word. If the word comes between the words apple and pear alphabetically, print a message that tells the user that the word is valid, otherwise, tell the user the word is out or range. 5. Write a Python program that prompts the user for a multiple of 5 between 1 and 100. Print a message telling the user whether the number they entered is valid. Copyright StatementThis work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, this material is a modification by Ehren Bucholtz and Robert Belford of CS-POGIL content, with the original material developed by Lisa Olivieri, which is available here. What symbol indicates that some condition must be tested in a flowchart?Introduction to Programming 04. What logical operator reverses the truth of a Boolean expression?Using the NOT operator, we can reverse the truth value of an entire expression, from true to false or false to true.
When using the ____ operator one or both Subexpressions must be true for the compound expression to be true?With the Boolean OR operator, you can connect two Boolean expressions into one compound expression. At least one subexpressions must be true for the compound expression to be considered true, and it doesn't matter which. If both subexpressions are false, then the expression is false.
What symbol is used to represent a Boolean expression?The OR symbol has its roots in Boolean algebra, a field of mathematics concerned with the logical relationship between statements in an expression. Each statement in the expression returns a truth value of either true or false -- 1 or 0, respectively.
|