CSC111 Lab 3 2014

From dftwiki3
Revision as of 07:22, 12 February 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- <br /> =If Statements: Loosening Up= Using the code snippet shown below, change the ''boolean expression'' inside the '''if-statement''' so that the program beha...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 07:22, 12 February 2014 (EST)



If Statements: Loosening Up

Using the code snippet shown below, change the boolean expression inside the if-statement so that the program behaves the required way:

# Validity test example
x = int( input( "Please enter an integer: " ) )
if    ...      :
    print( "valid input" )
else:
    print( "invalid input" )


Example: put a boolean expression such that the program will print valid input if x is an integer different from 0.

In this case you would change the program to:

# Validity test example
x = int( input( "Please enter an integer: " ) )
if    x != 0     :
    print( "valid input" )
else:
    print( "invalid input" )


Test Case #1
modify the boolean expression so that the program outputs valid input only if x is greater than 10. Run your program and verify that it works for values equal to 0 and values not equal to 0.


Test Case #2
modify the boolean expression so that the program outputs valid input only if x is greater between the values of 10 and 20, excluded. The values 10 and 20 are not considered valid in this test case.


Test Case #3
modify the boolean expression so that the program outputs valid input only if x is greater between the values of 10 and 20, included. The values 10 and 20 are considered valid in this test case.


Test Case #4
modify the boolean expression so that the program outputs valid input only if x is an even number only.


Test Case #5
modify the boolean expression so that the program outputs valid input only if x is divisible by 2 and divisible by 5. Test your program with numbers such as 18, 20, 22, -10, etc.


Test Case #6
modify the boolean expression so that the program outputs valid input only if x is divisible by 2 and between 0 and 100, included. Verify that your program correctly accepts 0, 10, 90, 100, but rejects not -10

99, or 101.