Python Code and Output Quiz

RoomierCommonsense avatar
RoomierCommonsense
·
·
Download

Start Quiz

Study Flashcards

42 Questions

Which of the following is an example of a procedural programming language?

C

Which of the following is an example of an object-oriented programming language?

C#

Which of the following is an example of an interpreted programming language?

Python

Which of the following is an example of a compiled programming language?

C++

Which of the following is the correct definition of hardware?

The physical aspect of the computer that can be seen

Which of the following is considered an input device?

Keyboard

What is the purpose of high-level programming languages?

Make programming less error-prone and less tedious

Which of the following statements about Python 3 is true?

Python 3 is a newer version, but it is not backward compatible with Python 2.

Which of the following programming languages is an object-oriented programming language?

Java

Which of the following programming languages is interpreted?

Python

Is Python syntax case-sensitive?

True

Which of the following functions returns the current time in milliseconds since midnight, January 1, 1970?

time.time()

Which of the following functions causes an error?

int("034")

What will be displayed by the following code? print("A", end = ' ') print("B", end = ' ') print("C", end = ' ') print("D", end = ' ')

A B C D

In Python, a string literal is enclosed in __________.

single-quotes

Which of the following is the result of the code x=1; x=2*x+1; print(x)?

3

What will be displayed by the following code? x=1; x = x + 2.5; print(x)

3.5

What will be displayed by the following code? x, y = 1, 2; x, y = y, x; print(x, y)

2 1

Which of the following is the correct input for the code? x, y = eval(input("Enter two numbers: "))

1, 2

Which of the following code displays the area of a circle if the radius is positive?

if radius > 0: print(radius * radius * 3.14159)

The following code displays ___________. temperature = 50 if temperature >= 100: print('too hot') elif temperature < 100: print('just right') else: print('too cold')

'just right'

What is the output of the following code snippet? i = 1 while i < 10: print(i, end=' ') i = i + 2 if i == 5: i = 9

1 3 5 7 9

What is the output of the following code snippet? i = 1 while i .= 9: print(i, end=' ') i = i + 1 if i == 9: print('End')

1 End (infinite loop)

Which of the following is the physical aspect of the computer that can be seen?

Hardware

Which parts of the computer store program code?

Secondary storage

Which of the following hardware devices is NOT considered an input device?

Monitor

Which of the following is true about the Python language?

Python is an interpreted programming language.

What is the difference between an editor and an interpreter?

An editor converts program files into an executable program; an interpreter reads and executes program files.

Which of the following is an example of a high-level programming language?

C++

What is the purpose of a compiler?

To convert high-level language program into machine language program.

Which of the following is an example of a high-level programming language?

Python

Which of the following statements about Python 3 is true?

Python 3 is a newer version, but it is not backward compatible with Python 2.

What is the result of the code x=1; x = x + 2.5; print(x)?

4.5

Which of the following is a valid identifier in Python?

mile

Which of the following is the correct comparison operator in Python?

==

Which of the following code snippets will display the area of a circle if the radius is positive?

if radius > 0: print(radius * radius * 3.14159)

What is the output of the following code snippet?

135

What is the output of the following code snippet?

1 End (infinite loop)

Which of the following functions returns the current time in milliseconds since midnight, January 1, 1970?

round(3.9)

Which of the following functions cause an error?

int("034")

What will be displayed by the following code?

print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = ' ')

A B C D

Which of the following statements is correct?

s = "Chapter " + str(1)

Study Notes

Programming Languages

  • Procedural programming language: Example is C
  • Object-oriented programming language: Example is Java
  • Interpreted programming language: Example is Python
  • Compiled programming language: Example is C++

Hardware

  • Hardware refers to the physical components of a computer
  • Input device: Example is a keyboard
  • Correct definition of hardware: Physical components of a computer that can be seen

Programming Concepts

  • High-level programming languages: Purpose is to make programming easier and more efficient
  • Example of high-level programming language: Python
  • Compiler: Purpose is to translate high-level language into machine code
  • Object-oriented programming language: Example is Python
  • Interpreted programming language: Example is Python
  • Python syntax is case-sensitive
  • int(round(time.time() * 1000)) returns the current time in milliseconds since midnight, January 1, 1970

Python Code

  • x=1; x=2*x+1; print(x) returns 3
  • x=1; x = x + 2.5; print(x) returns 3.5
  • x, y = 1, 2; x, y = y, x; print(x, y) returns 2 1
  • Correct input for x, y = eval(input("Enter two numbers: ")) is a string of two numbers separated by a comma
  • import math; r = float(input("Enter radius: ")); if r &gt; 0: print(math.pi * r ** 2) displays the area of a circle if the radius is positive
  • temperature = 50; if temperature &gt;= 100: print('too hot'); elif temperature &lt; 100: print('just right'); else: print('too cold') returns 'just right'
  • i = 1; while i &lt; 10: print(i, end=' '); i = i + 2; if i == 5: i = 9 returns 1 3 9
  • i = 1; while i &lt;= 9: print(i, end=' '); i = i + 1; if i == 9: print('End') returns 1 2 3 4 5 6 7 8 9 End
  • String literal is enclosed in quotes
  • Valid identifier in Python: Example is myVariable
  • Correct comparison operator in Python: Example is ==
  • print("A", end = ' '); print("B", end = ' '); print("C", end = ' '); print("D", end = ' ') returns A B C D

This quiz tests your knowledge of Python code and output. Answer questions about the displayed code and predict the output.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Types of Programming Languages Quiz
5 questions

Types of Programming Languages Quiz

InnovativeRainbowObsidian avatar
InnovativeRainbowObsidian
Computer Science Basics Quiz
5 questions
Use Quizgecko on...
Browser
Browser