Python Questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the final result of this code? newsum = 0 for num in range(5): newsum = newsum + num 4 TypeError 10 (0,1,2,3,4)

10

How many times will this loop run? i = 0 while i <= 10: print("The count is", i) i += 1 0 10 11 infinite

11

How many times will this code print 'This is a low number'? i = 0 while i <= 9: if i <= 3: print('This is a low number') else: print('This is a high number') i += 1 4 6 3 9

4

Which statement best describes a loop? A loop is code that calls a particular block of code repeatedly. A loop is when one Python script uses code from another Python script. A loop is a logical error in the code that causes it to run endlessly. A loop is a line of code that skips to a different part of the code.

A loop is code that calls a particular block of code repeatedly.

Boolean conditional statements are part of a larger category of programming techniques called ... Algorithms Loops Control Structures Data types

Control Structures

When will this loop stop running? while True: print('hello') After it runs 1 time It will not end unless the code is interrupted It will run 6 times, once for each letter in 'hello' This code won't run because the sequence is not specified.

Correct answer: It will not end unless the code is interrupted

When will a particular elif or the else statement be executed? Never, elif statements are just there for documentation When the if statement is False When the if statement is True Only when the if and all prior elif statement have been evaluated as False.

Correct answer: Only when the if and all prior elif statement have been evaluated as False.

Which statement is true about loops? The loop begins with either the `for` or `while` keyword and ends with a comma. The loop begins with either the `for` or `while` keyword and ends with a colon. The loop begins with the `def` keyword and ends with an ending parenthesis. The loop begins with either the `loop` or `def` keyword and ends with a comma.

Correct answer: The loop begins with either the `for` or `while` keyword and ends with a colon.

Tuples are immutable AND sets exclude duplicates, true or false?

Correct answer: True

Which of these creates a blank dictionary? d = {] d = [} d = () d = {}

Correct answer: d = {}

Which of the following is an appropriate if statement if x > 7 x > 7 if x > 7: if:

Correct answer: if x > 7:

Each pair of items in a dictionary is known as what kind of pair? index:value pair key:index pair key:value pair field:value pair

Correct answer: key:value pair

Which of these creates the sequence 1,2,3,4,5? range(1,5) range(6) range(1,6) range(5)

Correct answer: range(1,6)

If I have an if statement, then I must also have an else statement (True/ False)

False

The 'is' keyword evaluates if two objects have the same value. (True/ False)

False

The Boolean objects True and False in Python are the same as the strings 'TRUE' and 'FALSE' (True/ False)

False

The main difference between a for loop and a while loop is a for loop continues running as long as the condition is True (True/False)?

False

Which of the following statements are true about lists? Lists are immutable and non-ordered Lists are immutable and mutable Lists are mutable and ordered Lists are immutable and ordered

Lists are mutable and ordered

Lists can include different types of data? (True/ False)

True

The code that is part of my if statement must be indented at least one level. (True / False)

True

the if, elif and else statements must all be concluded with the colon ( : ). (True/ False)

True

Which of these lines of code will create a list called 'a' that consists of ['Washington', 'Wyoming', 'Vermont'] where: visited = ['Arizona', 'North Carolina', 'Washington', 'Wyoming', 'Vermont', 'Alabama', 'Florida'] a = visited['Washington', 'Vermont'] a = visited[2:5] a = visited[2:4] a = visited[1:4]

a = visited[2:5]

Which of these returns 'Tuesday' given: duties = {'Smith': 'Monday', 'Davis':'Tuesday', 'Carlson':'Wednesday', 'Smith':'Thursday', 'Kilmer':'Friday'} duties['Tuesday'] duties['davis'] return.('Tuesday') duties['Davis']

duties['Davis']

The keyword that allows a conditional structure to have multiple different conditional statements with unique conditions is: if else elif asif

elif

Which keyword can be used to see if an item resides inside of a data collection. in has and is

in

Which of these lines of code creates an empty list variable called "mylist"?

mylist = []

The three Boolean operators we learned in this Unit not or and

not, or, and

Which of these lines of code will insert a 0 in the nums list just after the 3 where: nums = [9,5,4,1,3,6,7,8,'test','score','judge'] nums.insert(5,0) insert(5,0) in nums insert.nums(5,0) nums(5,0).insert()

nums.insert(5,0)


Ensembles d'études connexes

NURS 321: Leadership Module 2.02

View Set

Prep U Practice Questions (Nutrition)

View Set

marketing module 4 chapter 12 developing new products

View Set

Chapter 8: Political Parties: American Government

View Set

Chapter 1 Science and the Universe

View Set