Python short one to three line answers
45 a. Write a conditional that multiplies the value assigned to pay by one-and-a-half if worked_overtime contains the value True.
b. Assume that c is a variable that has been given a string value. Write an expression whose value is True if and only if c is NOT what is called a whitespace character(space,tab, or newline)
c. Assume that c is a variable that has been given a string value. Write an expression whose value is True if and only if c is what is called a whitespace character(space,tab, or newline)
Q45)
a) For The Conditional statement we have first check whether worked_overtime is true of not and if it is true then pay = pay *1.5
In Python We use a IF statement to do this
Expression will be : if worked_overtime == True : pay *= 1.5
Here we have used == ( equals operator ) that check true for worked_overtime and if true then pay*=1.5 is same as pay = pay * 1.5
b) If c is then it should be white space , newline character , tab .
So in the expression we will check three things 1. c is white space 2. c is newline 3. c is tab and we combine them using or operator and if anyone one gets true then value is false by negating it and if any condition is not true then true will be the value
Expression will be : !(c == ' ' or c== '\n' or c == '\t')
In Python ' ' means White space , '\n' means newline , '\t' means tab so we use == ( equals operator ) to compare each and we have negate( ! ) the output of inner bracket .
c) In this we have do the Opposite of what we did in Last Part b
So in the expression we will again check three things 1. c is white space 2. c is newline 3. c is tab and we combine them using or operator and if anyone one gets true then value is true .
Expression will be : (c == ' ' or c== '\n' or c == '\t')
Here we just remove the Negation operator and we get the desired expression
This is how we can write all three expression in one line in Python for each part
Thank You
If u like the answer then do Upvote it and have any doubt ask in comments
Get Answers For Free
Most questions answered within 1 hours.