CSC111 Exercise Boolean Variables
--D. Thiebaut (talk) 09:02, 14 February 2014 (EST)
Contents
Boolean Variables
Rewrite the following Python statements taking the boolean expressions in the if-statement and replacing them with boolean variables.
Example:
x = int( input( "> " ) )
if x != 0:
print( "statement 1 " )
- would become
x = int( input( "> " ) )
isNot0 = x != 0
if isNot0:
print( "statement 1 " )
Exercise 1
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 2
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 3
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 4
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 5
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 6
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 7
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 8
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )
Exercise 9
x = int( input( "> " ) )
if x % 2 == 0 and x % 5 == 0:
print( "statement 1" )