Python Programming Quiz 1

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
Learn about Our Editorial Process
| Written by Tomroy
T
Tomroy
Community Contributor
Quizzes Created: 1 | Total Attempts: 414
Questions: 11 | Attempts: 414

SettingsSettingsSettings
Python Programming Quiz 1 - Quiz

End of first quarter test.


Questions and Answers
  • 1. 

    What is missing at the end of the following line? if x<=5

    • A. 

      ;

    • B. 

      #

    • C. 

      .

    • D. 

      :

    Correct Answer
    D. :
    Explanation
    A colon ":"

    Rate this question:

  • 2. 

    Which is correct if the input I want is specifically a number?

    • A. 

      Input("Please enter your age")

    • B. 

      Print "Your age is 25"

    • C. 

      Raw_input("Please enter your age")

    • D. 

      Year=input("Please enter your age")

    Correct Answer
    D. Year=input("Please enter your age")
    Explanation
    Although the word "year" doesn't correlate to age, the variable name can be anything that fits within the parameters of python.

    Rate this question:

  • 3. 

    A1=random._______(1,10)

    Correct Answer
    randint
    Explanation
    The correct answer is "randint". The function "randint" is used to generate a random integer between two specified numbers, in this case, between 1 and 10.

    Rate this question:

  • 4. 

    Without using Python to check your results, write the code here that will ask someone to input their first name and then their last name (2 input statements) and then print them out on the same line.

  • 5. 

    Which of the following are correct?

    • A. 

      Print " Hello World "

    • B. 

      Print = "Hello World"

    • C. 

      Print " 'Hello World' "

    • D. 

      Print ' Hello Word '

    Correct Answer(s)
    A. Print " Hello World "
    C. Print " 'Hello World' "
    D. Print ' Hello Word '
    Explanation
    The print = "Hello World" is not correct because "print" is a Python keyword and cannot be used as a variable name.

    Rate this question:

  • 6. 

    Read through the following code for the computer to guess a number.  There are 2 lines in bold.  Why is the starting number "+1" and the ending number "-1"import random print "Please enter the range you would like me to guess from."starting = input("Enter starting number: ")ending = input("Enter ending number: ")your_num = input("Enter your number: ") guess = "F" while guess == "F":     comp_guess = random.randint(starting,ending)     if comp_guess == your_num:        guess = "T" import random print "Please enter the range you would like me to guess from."starting = input("Enter starting number: ")ending = input("Enter ending number: ")your_num = input("Enter your number: ") guess = "F" while guess == "F":     comp_guess = random.randint(starting,ending)     if comp_guess == your_num:        guess = "T"     elif comp_guess > your_num:        print "% .0f is too high" % comp_guess        ending = comp_guess - 1    else:        print "% .0f is too low" % comp_guess        starting = comp_guess +1 print "I guesed your number % .0f" %comp_guess print "I guesed your number % .0f" %comp_guess

  • 7. 

    In the following code, what does bileng equal (represent)?binary = raw_input("Enter a Binary Number: ")bileng = len(binary)

  • 8. 

    Write a statement that picks a random number between 7 and 35 using the variable name "number"

    Correct Answer(s)
    number = random.randint(7,35)
    Explanation
    The given answer correctly assigns a random number between 7 and 35 to the variable named "number" using the random.randint() function. This function takes two arguments, the lower and upper bounds, and returns a random integer within that range. In this case, it will generate a random number between 7 and 35 (inclusive) and assign it to the variable "number".

    Rate this question:

  • 9. 

    ______ = input("please enter a number")

    Correct Answer(s)
    anything
    Explanation
    Any variable name that is consistent with Python documentation.

    Rate this question:

  • 10. 

    What line of code is necessary before executing a cammand picking a random number?

    Correct Answer(s)
    Import Random
    Explanation
    The line of code "Import Random" is necessary before executing a command to pick a random number because it imports the Random module in Python. The Random module provides functions that allow us to generate random numbers. By importing this module, we can access these functions and use them to pick a random number in our code.

    Rate this question:

  • 11. 

    What is wrong with thr follong code?while guess = "F":

Related Topics

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.