ISE Quizzes

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is wrong with the following code snippet? num = 78A

78A is not a valid value in a Python program

To store a value for later use in Python, the programmer needs to create a:

variable

Which of the following statements causes Python to report an error?

x = 17 + "18.4"

What symbol is used to begin a comment in a Python program?

#

A sequence of steps that is unambiguous, executable, and terminating is called:

an algorithm

How is a value stored in a variable?

an assignment statement

What is the output of the code snippet given below? s = "abcde" length = len(s) i = 1 while i < length : print(s[i]) i = i + 1

bcde

Which of the following loops executes exactly 10 times?

for i in range(1, 11) : i = 1

What functions can be used to convert a string into a number?

int and float

Assume the following variable has been declared and given a value as shown: from random import randint number = randint(0, 27) * 2 + 3 What are the smallest and largest values that may be assigned to number?

3, 57

What is it called when you join two strings together in Python?

concatenation

Which of the following statements correctly calculates the average of three numbers: num1, num2, and num3?

( num1 + num2 + num3 ) / 3

What is the definition of a nested statement?

. A decision statement that is contained inside the statement block of another decision statement

What extension is used for Python files?

.py

What is the index value of the letter 'h' in the string below? message = "hello"

0

What is the output of the code below? num = 1 for val in range(0, 4) : sum = val for x in range(0, val, num) : sum = sum + x print(sum , end = " ")

0 1 3 6

What is the output of this loop? i = 0 found = False while i < 20 and found != True : sum = i * 2 + i * 3 print(sum, end=" ") if sum > 50 : found = True i = i + 1

0 5 10 15 20 25 30 35 40 45 50 55

What is the value of result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 / num2 / num3 print(result)

0.25

Consider the following code segment: c = 2 b = 1 if b == 0 : c = c + 1 else : c = c - 1 print(c) What value is printed by this code segment?

1

Consider the following code segment: numPizzas = 1 numPeople = 4 if numPeople == 5 : numPizzas = 2 After this code segment executes, what value is in the variable numPizzas?

1

Consider the following pseudocode. What does it produce? Set a = 0 Set b = 0 Set c = 1 Set d = 1 Report the value of d Repeat until a equals 10 Set d = b + c Set b = c Set c = d Add 1 to a Report the value of d

1 1 2 3 5 8 13 21 34 55 89

How many times will the following loop run? i = 0 while i < 10 : print(i) i = i + 1

10

What is the output of this code snippet if the user enters the numbers 1 2 3 4 -1? total = 0 validNumber = True while validNumber : value = int(input("Please enter a positive value < 100: ")) if value > 0 and value < 100 : total = total + value else : validNumber = False print(total)

10

What will be printed by the statements below? for ctr in range(10, 5, -1) : print(ctr, end = " ")

10 9 8 7 6

How many times does the following loop execute? i = 0 found = False while i < 100 and found != True : i = i + 1 print(i, end = " ") j = i * i if i * i * i % j == j : found = True

100 times

How many times does the loop execute in the following code fragment? for i in range(0, 50, 4) : print(i)

13 times

Assuming a user enters 30, 20, and 10 as the input values, what is the output of the following code snippet? num1 = int(input("Enter a number: ")) num2 = int(input("Enter a number: ")) num3 = int(input("Enter a number: ")) if num1 > num2 : if num1 > num3 : print(num1) else : print(num3) else : if num2 > num3 : print(num2) else : print(num3)

30

Consider the following code segment: if count > 0 : x = x + 1 print(x) If count is initialized to -1 and x is initialized to 4 then the value displayed by this code segment is:

4

How many times does the while loop execute? s = "abcdEfghI" found = False count = 0 while found == False : if s[count].isupper() : print(letter) found = True count = count + 1

5 times

What is printed by the following code snippet? num = int("45") * float("1.5") print(num)

67.5

What will be printed by the statements below? val = 1 sum = 0 while val < 5 : sum = sum + val val = val + 1 print(sum)

10

Consider the following pseudocode. What does it produce? Create a list of consecutive integers from two to n (2, 3, 4, ..., n). Initially, let p equal 2. Repeat the following steps until p is greater than n: Remove all of the multiples of p less than or equal to n from the list. If the list contains a number greater than p Find the first number remaining in the list greater than p. Replace p with this number. Otherwise set p equal to n + 1

all prime numbers up to n

Which line in the following program is a comment line? 1: print("Your lucky number is...") 2: lucky = 7 3: # Display the lucky number 4: print(lucky)

line number 3

Which statement correctly creates a new variable by combining the two string variables: firstName and lastName?

name = firstName + lastName

What is printed by the following code snippet: street = " Main Street" address = 123 + street print(address)

nothing is printed, this code snippet causes an error

Which of the following is considered an equivalent while loop for this for loop? s = 0 for i in range(1, 10) : s = s + i

s=0 i = 1 while i < 10: s = s + 1 i = i + 1

What must be done first before you can use a function from the standard library?

the function must be imported

What is wrong with the following code snippet? ((num1 + num2) * num3 / 2 * (1 - num4)

there is an extra parenthesis

What output is generated by the following code snippet? firstName = "Pamela" middleName = "Rose" lastName = "Smith" print(firstName[0], middleName[0], lastName[5])

nothing, this causes an index of bounds error

Which of the following loops will print the odd numbers between 0 and 20?

num = 1 while num < 11 : value = num * 2 - 1 print(value, " ") num = num + 1

What will be the values of the variables num1 and num2 after the given set of assignments? num1 = 20num2 = 10num1 = num1 + num2 / 2num2 = num1

num1 = 25.0, num2 = 25.0

Which type of error is usually the most difficult to locate in your program?

Logic Error

What is printed by the following code snippet? name = "Robert" formalName = name.upper() print(formalName)

ROBERT

What will be the range of the random numbers generated by the following code snippet? from random import randint randomNum = randint(1,50)

Between 1 and 50

What is the output of the following code snippet when the user enters 75 as the grade? grade = int(input("Enter student grade: ")) if grade >= 90 : letterGrade = "A" if grade >= 80 : letterGrade = "B" if grade >= 70 : letterGrade = "C" if grade >= 60 : letterGrade = "D" else : letterGrade = "E" print(letterGrade)

D

Which of the following activities can be simulated using a computer? I. Waiting time in a line at a restaurant II. Tossing a coin III. Shuffling cards for a card game

I II and III

What does the following code do? from random import randint sum = 0 COUNT = 1000 for i in range(1,COUNT + 1) : sum = sum + randint(0, 100) print(sum / COUNT)

It calculates the average of 1000 random numbers between 0 and 100

What is wrong with the following code snippet: num1 = 10 num2 = 20 num3 = 30 total = Num1 + Num2 + Num3

Python is case sensitive so Num1, Num2, and Num3 are undefined

What error will Python display when it attempts to execute the following if/else statement? if a = b : print("Equal") else : print("Not Equal") if a > b : print("a is larger") else : print("b is larger")

Python will display an error indicating that = is invalid syntax

What error will Python display when it attempts to execute the following if/else statement? if a == b : print("Equal") else : print("Not Equal") if a > b : print("a is larger") else : print("b is larger")

Python will display an error indicating that there is a problem with the indentation

What does the following code compute? sum = 0 count = 0 value = input("enter an integer") while value > 0 : sum = sum + value count = count + 1 value = input("enter next integer") result = sum * 1.0 / count print(result)

The average of all the positive integers in the input

Which of the following options refers to the technique of simulating program execution on a sheet of paper?

Tracing

Suppose that a program asks a user to enter multiple integers, either positive or negative, to do some calculation. The data entry will stop when the user enters a certain value to indicate the end of the data. What value should the code use as the sentinel?

an alphabetic character

What is the wrong with the following code snippet? grade = int(input("Enter student grade: ")) if grade >= 90 : letterGrade = "A" if grade >= 80 : letterGrade = "B" if grade >= 70 : letterGrade = "C" if grade >= 60 : letterGrade = "D" else : letterGrade = "E" print(letterGrade)

anyone with a grade higher than 60 will receive a D

When a function is called, the values placed in parentheses are referred to as

arguments

Assume that you have an integer variable, pennies, that currently contains an integer number of pennies. Which statement determines the number of dollars and cents for that number of pennies?

dollars = pennies // 100cents = pennies % 100

The operator >= stands for

greater than or equal to

What range of numbers are generated by the random() function?

greater than or equal to zero and less than one

Which of the following code snippets displays the output exactly 10 times?

i = 0 while i <= 10 : print("This is example 1.") i = i + 1

What are the values of i and j after the following code snippet executes? i = 20 j = 70 count = 0 while count < 5 : i = i + i i = i + 1 j = j - 1 j = j - j count = count + 1 print(i) print(j)

i = 671, j = 0

Consider the following code snippet. What should be placed in the blank to cause a message to be displayed when the user enters the same letter twice in a row? letter = input("Enter the next letter in the alphabet: ") while letter != "": previous = letter letter = input("Enter the next letter") if ________________________ : print("Duplicate input")

letter==previous

Which condition will cause the statement block of the if statement to execute only when count is 0?

if count == 0 :

The following program is supposed to print a message any time the user enters two consecutive values that are the same. What line of code must be inserted in the blank so that the program will achieve this goal? value = int(input("Enter a value: ") inputStr = input("Enter a value: ") while inputStr != "" : previous = value value = int(inputStr) ____________________ print("Found consecutive values that are the same") inputStr = input("Enter a value: ")

if previous == value

Which statement correctly tests if the user entered the letter Y?

if userInput == "Y" :

What is the output of the code fragment given below? i = 0 j = 0 while i < 27 : i = i + 2 j = j + 1 print("j =", j)

j = 14

Which of the following variables should be coded as a constant in Python?

pi: 3.14159

Which of the following code segments will display Hello World! when it is run?

print("Hello", "World!")

Given the code snippet below, what code is needed to print the person's initials? firstName = "Pamela" middleName = "Rose" lastName = "Smith"

print(firstName[0], middleName[0], lastName[0])

Which of the following is the correct code snippet for throwing a pair of dice to get a sum of the numbers on two dice between 2 and 12 with the same probability as when throwing actual dice?

randint(1, 6) + randint(1, 6)

Which of the following expressions will generate a random integer in the range -20 to 20, inclusive, where each value has an equal chance of being generated?

randit(-20,20)


संबंधित स्टडी सेट्स

The Presidency of Thomas Jefferson 1801-1809

View Set

ASVAB Arithmetic Reasoning section

View Set

Abnormal Psychology Chapter 6 Quiz

View Set

Chapter 6_Inside classes and objects

View Set

Motivation and Emotion Exam 1 (chapter 1-3)

View Set

Secondary survey chapter 12 Arnheim pp, Types of shock, Medical Terminology, Injuries & Deformities of the hand, Budgeting terms, BOC Prep and NATA-BOC Exam Secrets Study Guide, BOC

View Set

ABEKA 9TH GRADE BIBLE KINGS OF ISRAEL SEMESTER VERSE EXAM(VERSES FOR MIDTERM)

View Set