Quiz #2 for October 8, 2020

Please use your Python system (IDLE or something else) to compute the following. Be prepared to show your work!

  1. If you want to read an integer from the input, which of the following should you use?

    1. input("Please type an integer: ")
    2. int(input("Please type an integer: "))
    3. input(int("Please type an integer: "))
    4. int(str(input("Please type an integer: "))))

    Answer: (b). For (a), input() returns a string, not an integer. Choice (c) has the right idea, but you have the input and int reversed. As the prompt isn’t a string that represents an integer, the int() will fail, and the input() will never be executed. Choice (d) will work, but the str() is unnecessary as input() returns a string. So you should omit it, and that’s choice (b).


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
MHI 289I, Programming for Health Informatics
Version of October 12, 2020 at 10:51PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh