CSC111 Exercise Boolean Variables

From dftwiki3
Revision as of 09:02, 14 February 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- =Boolean Variables= Rewrite the following Python statements taking the boolean expressions in the '''if-statement''' and replacing them with boolean variables. E...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 09:02, 14 February 2014 (EST)


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" )