Use the if function to label items that are over N$15 as HIGH and those below N$15 AS LOW
Question
Use the if function to label items that are over N15 AS LOW
Solution
Here is a simple example of how you can use the if
function to label items that are over N15 as 'LOW' in Python:
def label_price(price):
if price > 15:
return 'HIGH'
else:
return 'LOW'
# Test the function
print(label_price(20)) # Outputs: HIGH
print(label_price(10)) # Outputs: LOW
In this code:
- We define a function
label_price
that takes a price as an argument. - Inside the function, we use an
if
statement to check if the price is greater than 15. - If the price is greater than 15, the function returns the string 'HIGH'.
- If the price is not greater than 15 (i.e., it is 15 or less), the function returns the string 'LOW'.
- We then test the function with two examples: a price of 20 (which is greater than 15) and a price of 10 (which is less than 15).
Similar Questions
Which function can be used in cell C16 to determine the lowest price value?(1)Group of answer choices=MINIMAL=LOWEST=MIN=LOW
Write an if-else statement to check if the sum of elements in "colVec" is greater than 10
% Write an if-else statement to check if the sum of elements in "colVec" is greater than 10
If the element's value is less than or equal to 60, then output 'Sample ', followed by the element's index, and ' is ok'.
If 15% of x = 20% of y, then x : y is :(a) 3 : 4 (b) 4 : 3 (c) 17 : 16 (d) 16 : 17Options :abcd
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.