IT 116: Introduction to Scripting
Quiz 6 Answers

  1. If you wanted to use the functions in the math module inside your script, what statement should appear at the top of the script?
    import math
  2. If you wanted to print the value of pi from the math module, what statement would you use?
    print(math.pi)
  3. Are the series of number created by the function is the random module really random?
    no. they are a pseudorandom number sequence
  4. If you wanted to use the functions in the random module inside your script, what statement should appear at the top of the script?
    import random
  5. What do you call the initial value given to an algorithm used to generate "random" numbers.
    seed
  6. Write the single Python statement you would use to return the value of the expression interest * principle from within a function.
    return  interest * principle
  7. Write the single Python statement you would use to return True if the parameter number_1 were greater than the parameter number_2, but otherwise return False.
    return  number_1 > number_2
  8. Write the single Python statement you would use to return True if the parameter number_1 were equal to the parameter number_2, but otherwise return False.
    return  number_1 == number_2
  9. Write the Python statement you would use to return True if the parameter number were less than 0, but otherwise return False.
    return  number < 0
  10. Write the Python function get_positive which takes no parameter and returns a number greater than 0. This function should use the input function to ask the user for a number and convert it to an integer. It should then keep looping until it gets a number that is greater than 0. When it gets such a number, it should return that number.
    def get_positive():
    	number = int(input("Integer greater than 0: "))
    	while number <= 0:
    	     print(number, "is not greater than 0")
    	     number = int(input("Integer greater than 0: "))
    	return number