ON PYTHON
Exercise 1. For each of the relational/logical expressions listed in exercise1.py determine whether the expression evaluates to True or False. Place a comment after each expression with the truth value and submit the updated exercise1.py file to the dropbox. For example, x = 10 y = 11 x < y # True insert a comment after the expression
x = 10
y = 11
a = 12.5
b = -5.2
x < y
# True
x < y and a < b
x * y > 100 or a < b
not ( x + y == 21 )
not ( x < y ) or ( a > b )
x % 2 == 0 and y % 2 == 1
Exercise 2. Convert the two if-statements in the exercise2.py file into a single if-else-statement that produces the same output.
# convert the two if-stmts to one if-else-stmt
msg = input( 'Enter message: ' )
# replace these statements with a single if-else statement
if msg == 'first time':
print ( 'start up message' )
if msg != 'first time':
print ( 'continuing message' )
Exercise 3. Insert a conditional statement at the end of source code listed in exercise3.py that prints the error message ‘Error – value out of range’ if the user enters an integer value outside the range 0…100.
value = int( input( 'Enter the value: ') )
print( 'Value entered is', value )
# insert the additional statement(s) here
Exercise 1:
x = 10
y = 11
a = 12.5
b = -5.2
x < y
# True
x < y and a < b
#False
x * y > 100 or a < b
#True
not ( x + y == 21 )
#False
not ( x < y ) or ( a > b )
#True
x % 2 == 0 and y % 2 == 1
#True
Exercise 2:
# convert the two if-stmts to one if-else-stmt
msg = input( 'Enter message: ' )
# replace these statements with a single if-else statement
if msg == 'first time':
print ( 'start up message' )
else:
print ( 'continuing message' )
Exercise 3:
value = int( input( 'Enter the value: ') )
print( 'Value entered is', value )
# insert the additional statement(s) here
if(value < 0 or value > 100):
print('Error – value out of range')
Get Answers For Free
Most questions answered within 1 hours.