Document56

docx

School

Post University *

*We aren’t endorsed by this school

Course

241

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

10

Uploaded by ColonelTank11764

Report
11/19 that's 58% RETAKE THIS PRACTICE MILESTONE 11 questions were answered correctly . 8 questions were answered incorrectly . 1 What does the float data type contain? Positive and negative decimal numbers The sum of a real number and an imaginary number True or False Only positive whole numbers RATIONALE A float data type is numeric data containing positive or negative decimal values. CONCEPT Data Types Introduction Report an issue with this question 2 Attempting to use a variable before a value has been assigned to it is an example of which error type? Exception Logic Syntax NameError RATIONALE A NameError occurs when the interpreter attempts to use a variable that has not been defined. CONCEPT Debugging Operations Report an issue with this question 3 What will happen when the following script is run? a = 10 b = 20 c = 30 d = 0
if a > b: d = 4 elif b > c: d = 5 else: d = 6 print(d) 6 will be printed. 5 will be printed. 4 will be printed. 0 will be printed. RATIONALE 6 will be printed. Since "a" is less than "b," and "b" is less than "c," both the if and the elif statements evaluate to false. So the catch all else statement executes the assignment of 6 to "d." CONCEPT Multiple Conditions Report an issue with this question 4 If multiple variables are assigned these values on a single line, what would the value of "c" be? a, b, c, d, e = "Python", "is", "fun", "to", "learn" "learn" "fun" "Python" "is" RATIONALE Multiple variable assignment on a single line assigns the first value on the right side of the = to the first variable on the left and so on. In this example, "c" is the third variable and would be assigned the third value "fun." CONCEPT Using Strings Report an issue with this question
5 1 price = 12 2 quantity = 2 3 amount = price*quantity 4 5 if amount > 100: 6 if amount > 500: 7 print("Amount is greater than 500") 8 else: 9 if amount < 500 and amount > 400: 10 print("Amount is between 400 and 500") 11 elif amount < 500 and amount > 300: 12 print("Amount is between 300 and 500") 13 else: 14 print("Amount is between 200 and 500") 15 elif amount == 100: 16 print("Amount is 100") 17 else: 18 print("Amount is less than 100") For the sample script, when will line 6 be execut ed? When line three is equal to 500 When line three is invalid When line five evaluates to False When line five evaluates to True RATIONALE When the outermost if statement evaluates to True, the nested If code block will be executed. CONCEPT Debugging Conditional Statements Report an issue with this question 6 Using the boolean operator "or," if the first argument is True, and the desired output is True, there is no need to evaluate the second argument. This evaluation is also referred to as? Short-circuit Explicit
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Implicit Short-cut RATIONALE Short-circuit evaluation occurs when the evaluation of a logical expression stops because the overall value is already known. CONCEPT Boolean Operators Report an issue with this question 7 A new project can be created in Replit by clicking on the ________ button in the top right. search "+" (plus) run "-" (hamburger) RATIONALE "+" or "+ New" is used to create a new project in Replit. CONCEPT Guide to Using Replit Report an issue with this question 8 What is the logical step-by-step plan used to solve a problem called? Algorithm Pseudocode Machine code Program RATIONALE An algorithm is a logical step-by-step plan used to solve a problem. CONCEPT Thinking Through Examples Report an issue with this question 9 Python is a(n) _______________ language. assembly
interpreted machine compiled RATIONALE Python is an interpreted language, because the source code is not directly translated by the computer. Instead, an interpreter reads and executes the code. CONCEPT Programming Mindset Report an issue with this question 10 How would you convert a variable containing a string value to an integer? print(str(a)) print(int(a)) print(integer(a)) print("a") RATIONALE The int function can be used to convert an input string into an integer. CONCEPT String Operations Report an issue with this question 11 What is the output of the following script, if a = 9? if (a > 5 and a <= 10): print("Hello") else: print("Goodbye") Hello
Hello Goodbye Goodbye InvalidInput RATIONALE The if condition returns True, because 9 is greater than 5 and less than or equal to 10, thus printing Hello. CONCEPT Conditional Statements Report an issue with this question 12 This script asks you for your age and returns the last digit of it. What operator and divisor is missing on line 2? 1 num=int(input("Enter any number ")) 2 print("Last digit of your number is", num_____) "/10" "*10" "%10" "%2" RATIONALE The modulus operator works on integers and yields the remainder when the first operand is divided by the second. Any number modulo 10 will return the last digit. CONCEPT Drink Order Program Report an issue with this question 13 Read the following programs carefully. Which of these programs would produce the output shown below? lineslineslineslineslines3 2 myVar1 = '3' myVar2 = '2' lines = int(myVar1) + int(myVar2) myStr = myVar2 + ' ' + myVar1 + '\n'
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
result = (lines * 'lines') + myStr print(result) myVar1 = '3' myVar2 = '2' lines = int(myVar1) + int(myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = lines * 'lines' + myStr print(result) myVar1 = '2' myVar2 = '3' lines = int(myVar1) + int(myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = lines * 'lines' + myStr print(result) myVar1 = '2' myVar2 = '3' lines = int(myVar1) + int(myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = lines * ('lines' + myStr) print(result) RATIONALE The asterisk operator precedes the concatenation operator thus creating the desired output. CONCEPT Coding Your First Program Report an issue with this question 14 What number system contains 10 digits (0-9) and 6 characters (A-F)? Decimal Binary Octal Hexidecimal
RATIONALE Base 16 numbers or hexadecimal represent any number using 10 digits and 6 characters going from 0 to 9 and then A, B, C, D, E, and F. CONCEPT Using Integers and Floats Report an issue with this question 15 What is the purpose of the try and except statement in Python? To allow users to avoid inputting some data To detect and print out exception errors that will appear when the program runs To execute an exception block of statement(s) instead of an error To see functions that are executed and printed to the screen when an exception occurs RATIONALE If you know some sequence of instructions may have a problem, using a try and except statement allows you to execute some statement(s) instead of error presenting. CONCEPT Exceptions Report an issue with this question 16 The built-in string method index() returns what value? The first occurrence of the specified value The last occurrence of the specified value. -1 All occurrences of the specified value. RATIONALE The string index method finds the first occurrence of the specified value in a string. CONCEPT Functions and Methods Introduction Report an issue with this question 17 How would you increment the value of "a" by 10 and only use "a" once in the expression? a%10
a = a +10 a**10 a += 10 RATIONALE Python allows operations on the same variable, so we can perform addition and set the new value in the same step. CONCEPT Operators and Operands Report an issue with this question 18 Which is the first step for designing a program? Determine element conditions Determine the final output of the program Define the input elements of the program Look for repeating elements RATIONALE The first step to designing a program is defining the input elements for the program. CONCEPT Forming an Algorithm Report an issue with this question 19 You enter the line of code print("Python is fun!') and receive a SyntaxError: EOL while scanning string literal message. Which line of code can resolve this? print(Python is fun!) print()"Python is fun!" print('Python is fun!")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
print("Python is fun!") RATIONALE An improperly quoted string in print() will result in a SyntaxError: EOL while scanning string literal. CONCEPT Testing Report an issue with this question About Contact Us Privacy Policy Cookie Policy Terms of Use Your Privacy Choices © 2023 SOPHIA Learning, LLC. SOPHIA is a registered trademark of SOPHIA Learning, LLC.