Introduction to Python Programming (CSC 122 Lecture 1)
28 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What happens when you try to add an integer to a string in Python?

  • An error occurs because Python cannot implicitly convert the integer to a string (correct)
  • The integer is converted to a string and concatenated with the other string
  • The string is converted to an integer and added to the other integer
  • Python automatically converts both the integer and string to floats and performs addition

Which built-in functions can be used to convert an integer to a float in Python?

  • str()
  • int()
  • convert()
  • float() (correct)

What happens when you try to convert a non-numeric string to an integer in Python?

  • Python automatically converts the string to '0'
  • The string is converted to the ASCII code of its first character
  • An error occurs because Python cannot convert non-numeric strings to integers (correct)
  • The string is treated as 'NaN'

What is the result of the expression '10 / 2' in Python?

<p>5 (A), 5.0 (D)</p> Signup and view all the answers

How can you instruct Python to read data from a user during program execution?

<p>With the input() function (A)</p> Signup and view all the answers

What is the purpose of using 'int()' and 'float()' functions in Python according to the text?

<p>To explicitly convert between integers and floating-point numbers (A)</p> Signup and view all the answers

What will be the output of the following code snippet? x = 5 if x < 6: print('Less than 6') if x > 100: print('More than 100')

<p>Less than 6 (C)</p> Signup and view all the answers

What does a Boolean expression using comparison operators evaluate to?

<p>True/False or Yes/No (D)</p> Signup and view all the answers

In Python, which operator is used for 'Greater than or Equal to'?

<p>&gt;= (C)</p> Signup and view all the answers

Consider the code snippet. What will be printed? x = 4 if x > 2 : print('Bigger') else : print('Smaller')

<p>Smaller (A)</p> Signup and view all the answers

What happens in a two-way decision in programming?

<p>One path is chosen based on whether a logical expression is true or false (C)</p> Signup and view all the answers

Which of the following is true about comparison operators in Python?

<p>'=' is a comparison operator used to check equality (D)</p> Signup and view all the answers

What must be done to read a number from the user in Python?

<p>Convert the input from a string to a number (A)</p> Signup and view all the answers

What is the purpose of a # in Python code?

<p>Turn off a line of code (D)</p> Signup and view all the answers

What does the variable 'bigword' store in the given code snippet?

<p>The most common word in the file (D)</p> Signup and view all the answers

What does 'counts.get(word,0) + 1' accomplish in the code snippet?

<p>Adds 1 to the count of a word in the dictionary (D)</p> Signup and view all the answers

What does 'usf = int(inp) + 1' do in the given code snippet?

<p>Converts user input to an integer and adds 1 to it (D)</p> Signup and view all the answers

Why would you use comments in Python code?

<p>To turn off specific lines of code temporarily (B)</p> Signup and view all the answers

What type of language is Python considered to be?

<p>Interpreted language (B)</p> Signup and view all the answers

Which of the following is NOT a Python data type?

<p>Double (A)</p> Signup and view all the answers

What does a 'constant' refer to in Python?

<p>Fixed values whose value does not change (B)</p> Signup and view all the answers

What do 'Reserved Words' refer to in Python?

<p>Words that cannot be used as variable names (D)</p> Signup and view all the answers

What is a 'variable' in Python?

<p>A named place in memory where data can be stored and retrieved using a name (A)</p> Signup and view all the answers

What is the rule for Python variable names?

<p>Must start with a letter or underscore, followed by letters, numbers, and underscores (C)</p> Signup and view all the answers

What is the purpose of an assignment statement in Python?

<p>To assign a value to a variable (D)</p> Signup and view all the answers

What does an asterisk (*) represent in numeric expressions in Python?

<p>Multiplication (A)</p> Signup and view all the answers

What is the purpose of a 'Constant' in programming?

<p>To store fixed values that do not change during program execution (A)</p> Signup and view all the answers

What does '%' represent in numeric expressions in Python?

<p>Remainder (C)</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser