Question
What control structure are we using when we perform actions only if a specified condition exists? In a flow chart diagram, what shape represents a
- What control structure are we using when we perform actions only if a specified condition exists?
- In a flow chart diagram, what shape represents a true/false condition that must be tested
- What keyword is used at the beginning of a statement that checks a condition to determine whether a block of code should be executed or not?
What type of expression can result in true or false and is used for a conditional test.
- What is the difference between the (=) operator and the (==) operator?
- What type of operator checks if one value is NOT equal to another?
- What keyword can be used in a conditional statement to specify a block of code that should be run only if the previous condition was not met?
- When comparing strings, how does python determine which string is greater than another?
- What keyword is used to check a second potential condition following an if statement?
- How are statements lined up to indicate they are subject to an if statement?
Doing iffy statements
Do the python code for the following situations. I have highlighted variable names in bold.
- Print 'red' if the variable rgb is 10.
- Store the value of x into y if the value of z is less than 10.
- Set the price to 0, if the value of variable discount is more than the variable sales_price.
- If the number_of_dependents is more than 0, set withholding to 100; otherwise, set withholding to 1000.
- If the value of tax_paid is more than computed_tax, set refund to tax_paid minus computed_tax. Otherwise, set tax_owed to computed_tax minus tax_paid.
- If number_of_sides is 3, print 'It is a triangle'. Otherwise, print 'It is not a triangle'
Programming Exercise
For the following exercise, you can use the python files included in this assignment to do a simple program that will prompt the user to enter a number and then tell them if the number is odd or even.
It should look like so:
HINT: We can use the modulus operator to divide a value by 2 and see if it has a remainder of 1 or 0. If the remainder of a value divided by 2 is 1, then the number is odd, if the remainder is 0, then it is even.
Copy the python code in the section below. Copy and paste screenshots running the program to show it works properly for both even and odd numbers.
Enter a number: 1 Your number is odd
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
Step: 1
What control structure are we using when we perform actions only if a specified condition exists We are using a conditional control structure typically implemented using if statements to perform actio...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started