Select the code needed to complete the task below:
You are given a function which contains a non-working while loop. The function also accepts a positive integer (x). The while loop is in an infinite loop state, which would be unwise to run. The while loop continually decreases the value variable by 1. Your task is to fix the code so that the loop exits and returns the value variable when it is equal to x.
PCS Typing Questions MC

Flashcard
•
Computers
•
9th - 12th Grade
•
Hard
Quizizz Content
FREE Resource
Student preview

15 questions
Show all answers
1.
FLASHCARD QUESTION
Front
Back
Answer explanation
Explanation: You need to check to see if value is equal to x. If it is, then you will return the value variable.
Code (the code you write is italicized and bold, the underscores are where indentations should be):
def while_loop_finisher(x: int):
__value = -1
__while value:
____value -= 1
____if value == x:
______return value
2.
FLASHCARD QUESTION
Front
Select the code needed to complete the task below:
Write a function that iterates over a tuple(tup) and returns the position of the first odd number.
Back
Answer explanation
Explanation: We need to go through every number in the tuple and check to see if it is an odd number. You can check to see if it is an odd number by dividing the number by two and seeing if there is a remainder of 1.
Code (the code you write is italicized and bold, underscores are where indentations should be):
def return_position_of_odd(tup: tuple):
__for x in tup:
____if x % 2 == 1:
______return tup.index(x)
3.
FLASHCARD QUESTION
Front
Write a function that accepts two integers(a and b, where a < b) and returns the sum of all numbers between a and b (inclusive of a and b).
Back
Answer explanation
Explanation: We need to create a variable to store the total in. We then need to cycle through the range of numbers and add each number together inside of the variable. Then we return the total.
Code (the code you write is italicized and bold, underscores are where indentations should be):
def looping_sum(a, b):
__total = 0
__for x in range(a, b + 1):
____total += x
__return total
4.
FLASHCARD QUESTION
Front
Select the code needed to complete the task below:
Write a function that accepts two integers(a, b), it should sum up all the numbers from a to b (inclusive of a and b) and then return the sum divided by 2 as float.
Back
Answer explanation
Explanation: We need to create a variable to store the total in. We then need to cycle through the range of numbers and add each number together inside of the variable. Then we return the total divided by 2.
Code (the code you write is italicized and bold, underscores are where indentations should be):
def looping_sum(a: int, b: int):
__total = 0
__for x in range(a, b + 1):
____total += x
__return total / 2
5.
FLASHCARD QUESTION
Front
Select the code needed to complete the task below:
Add the line of code needed to accumulate the total of all values of a and then print the result.
Output should be 15.
Back
Answer explanation
Explanation: We need to add the values of a into the total variable.
Code (the code you write is italicized and bold, underscores are where indentations should be):
total = 0
for a in range(6):
__total += a
6.
FLASHCARD QUESTION
Front
Write a function that accepts an integer(i) which can only be 0 or 1 and returns the Boolean representation of that integer.
Back
Answer explanation
Explanation: We need to check to see if i is 0 or 1. If it is 1 we need to return True, and 0 would return False.
Code (the code you write is italicized and bold, underscores are where indentations should be):
def return_bool_integer(i):
__if i == 0:
____return False
__elif i == 1:
____return True
7.
FLASHCARD QUESTION
Front
Select the code needed to complete the task below:
Write a function that accepts an integer(i) which can only be 0 or 1. The function should return the inverse Boolean representation of that integer.
Back
Answer explanation
Explanation: We need to check to see if i is 0 or 1. If it is 1 we need to return False, and 0 would return True.
Code (the code you write is italicized and bold, underscores are where indentations should be):
def return_bool_integer(i):
__if i == 0:
____return True
__elif i == 1:
____return False
Create a free account and access millions of resources
Similar Resources on Quizizz
14 questions
7517 04 Subroutines local and global variables

Flashcard
•
10th Grade - University
10 questions
AP Computer Science Principles Unit 4 Review

Flashcard
•
9th Grade - University
12 questions
Python Functions

Flashcard
•
9th - 12th Grade
12 questions
CS Python Fundamentals Unit 4 Review

Flashcard
•
9th - 12th Grade
15 questions
Python Functions and Exceptions Review

Flashcard
•
9th - 12th Grade
12 questions
2.3.1 Cyber Securing Ecommerce Data

Flashcard
•
9th - 12th Grade
10 questions
Paper Practice 2

Flashcard
•
9th - 12th Grade
10 questions
CS Python Fundamentals Flashcard 4 Practice

Flashcard
•
9th - 12th Grade
Popular Resources on Quizizz
10 questions
Chains by Laurie Halse Anderson Chapters 1-3 Quiz

Quiz
•
6th Grade
20 questions
math review

Quiz
•
4th Grade
15 questions
Character Analysis

Quiz
•
4th Grade
12 questions
Multiplying Fractions

Quiz
•
6th Grade
30 questions
Biology Regents Review #1

Quiz
•
9th Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
50 questions
Biology Regents Review: Structure & Function

Quiz
•
9th - 12th Grade
Discover more resources for Computers
30 questions
Biology Regents Review #1

Quiz
•
9th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
50 questions
Biology Regents Review: Structure & Function

Quiz
•
9th - 12th Grade
20 questions
Taxes

Quiz
•
9th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression

Quiz
•
9th - 12th Grade
14 questions
Attributes of Linear Functions

Quiz
•
9th - 12th Grade
10 questions
Identifying equations

Quiz
•
KG - University
50 questions
Biology Regents Review 2: Ecology

Quiz
•
9th - 12th Grade