Unit 1 Milestone - Intro to Python

.pdf

School

Western Governors University *

*We aren’t endorsed by this school

Course

859

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

2

Uploaded by DeaconViper4079

Report
1 CONCEPT Using Integers and Floats 2 CONCEPT Testing 3 CONCEPT Data Types Introduction 4 CONCEPT Guide to Using Replit 5 CONCEPT Drink Order Program 6 CONCEPT Thinking Through Examples 7 CONCEPT Functions and Methods Introduction 8 CONCEPT String Operations 9 CONCEPT Using Strings 10 CONCEPT Boolean Operators 11 CONCEPT Programming Mindset 12 CONCEPT Debugging Conditional Statements 13 CONCEPT Operators and Operands 14 CONCEPT Forming an Algorithm 15 CONCEPT Debugging Operations 16 CONCEPT Coding Your First Program 18/19 that's 95% RETAKE 18 questions were answered correctly . 1 question was answered incorrectly . Decimal values are also called what? RATIONALE Base 10 numbers are also called decimal values and represent any number using 10 digits that go from 0 to 9. Report an issue with this question Which of the following is a valid method of creating multiline comments in Python? RATIONALE Unlike other programming languages, Python does not support multi-line comment blocks. The recommended approach is to use consecutive # single-line comments. Report an issue with this question Select the Python data type that consists of positive or negative numbers that have decimal values. RATIONALE A Float data type is numeric data containing positive or negative decimal values. Report an issue with this question Which panel is where you can see your code run? RATIONALE The output sandbox panel is where you will see your code in action. Report an issue with this question This script checks whether a person is eligible for voting or not. Which condition statement is missing on line 4? 1 age= int ( input ( "Enter your age" )) 2 if ___ >= 18 : 3 print ( "_____ for voting" ) 4 ____: 5 print ( "not eligible for voting" ) RATIONALE An else statement is optional and can be combined with an if statement. The else statement will be executed when the conditional expression in the if statement resolves to false. Report an issue with this question For a program to work correctly, the __________ and __________ have to be correct. RATIONALE The logic and syntax must be correct for a program to work correctly. Report an issue with this question Which built-in string method can be used to convert the first character of a string to uppercase and all remaining characters to lowercase? RATIONALE The capitalize() method converts the first character to uppercase. Report an issue with this question How would you add a single space when concatenating the two variables a="firstname" and b="lastname" ? RATIONALE In order to add a space between two strings during concatenation, the concatenation operator + can be used to add a space using two quotes. Report an issue with this question How would you construct a print statement to print the following quote? Programming isn't about what you know; it's about what you can figure out RATIONALE By using double quotes around the string, the contractions will print to the console correctly with a single quote. Report an issue with this question Which value pair will return True using the Boolean operator "and"? RATIONALE The and operator returns TRUE only when both arguments are set to TRUE. Report an issue with this question The _________ scans an entire program and attempts to convert the whole program at once to machine code. RATIONALE The compiler scans an entire program and attempts to convert the whole program at once to machine code. Report an issue with this question 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" ) Using the interactive debugger for the sample script, which line(s) would you set a breakpoint on to test the nested if statements? RATIONALE The nested if statements are on lines 6 and 9. Report an issue with this question What is the value of the following expression, if x = 8 and y = 2 ? (x + y) * 3 RATIONALE Following the order of operations, parentheses have the highest precedence 8+2=10, then multiplication 10 * 3 = 30. Report an issue with this question It is important that each individual __________ in an algorithm be well defined. RATIONALE For a program to function as expected, it is important that each step/instruction of the algorithm be well defined. Report an issue with this question Attempting to operate on variables with incompatible data types is an example of which error type? RATIONALE TypeErrors occur with trying to operate on incompatible types, such as when trying to concatenate a string to an int. Report an issue with this question Read the following programs carefully. Which of these programs would produce the output shown below? 555552 3 RATIONALE The asterisk operator precedes the concatenation operator forcing replication before concatenation, thus creating the desired output. Report an issue with this question Base 8 numbers ࠽? Base 10 numbers Base 2 numbers Base 16 numbers #Author: Sophia Description: this is a valid multiline comment# \\Author: Sophia Description: this is a valid multiline comment\\ ࠽? #Author: Sophia #Description: this is a valid multiline comment \\Author: Sophia \\Description: this is a valid multiline comment ࠽? Float String Boolean Integer files and configuration ࠽? output sandbox code editor menu bar else ࠽? elif if for ࠽? logic, syntax programming language, compiler variables, pseudocode logic, platform ࠽? Capitalize Upper Swapcase Index print (a b) ࠽? print (a + ' ' + b) print (a+b) print (a ' ' b) print(Programming isn't about what you know; it's about print('Programming isn't about what you know; it's about print(Programming isn't about what you know; it's about ࠽? print("Programming isn't about what you know; it's about A= FALSE, B=FALSE A= FALSE, B=TRUE A= TRUE, B=FALSE ࠽? A= TRUE, B=TRUE virtual machine program ࠽? compiler syntax 18 ࠽? 6,9 11,13 15,17 ࠽? 30 3.33 14 1000 ࠽? step output input condition ࠽? TypeError NameError Exception Syntax myVar1 = '3' myVar2 = '2' lines = int (myVar1) + int (myVar2) myStr = myVar2 + '\n' + myVar1 + '\n' result = str (lines) * lines + myStr print (result) myVar1 = '3' myVar2 = '2' lines = int (myVar1) + int (myVar2) myStr = myVar1 + ' ' + myVar2 + '\n' result = str (lines) * lines + myStr print (result) myVar1 = '3' myVar2 = '2' lines = int (myVar1) + int (myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = myStr * lines + str (lines) print (result) ࠽? myVar1 = '3' myVar2 = '2' lines = int (myVar1) + int (myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = str (lines) * lines + myStr print (result) UNIT 1 — MILESTONE 1: Program Basics Milestone 18/19
17 CONCEPT Multiple Conditions 18 CONCEPT Exceptions 19 CONCEPT Conditional Statements What will happen when the following script is run? a = 1 b = 2 c = 3 d = 0 if a > b: d = 4 else : if a > c: d = 5 print (d) RATIONALE 0 will be printed since neither the non-nested nor nested branch of the if statement evaluates to true. Report an issue with this question When are exceptions detected? RATIONALE Exceptions are detected when a program is executing. Report an issue with this question What is the output of the following program? temp_Fahrenheit = 104 if temp_Fahrenheit < 50 : print ( 'It is cold outside' ) elif temp_Fahrenheit > 80 : print ( 'It is hot outside' ) elif temp_Fahrenheit > 90 : print ( 'It is very hot outside' ) else : print ( 'It must be a nice day' ) RATIONALE The elif statement allows you to check multiple expressions. In this case, although the temperature is > 90, the first elif statement checking for the temperature > 80 precedes it and evaluates to true first. Report an issue with this question 4 will be printed NameError: name 'd' is not defined 5 will be printed ࠽? 0 will be printed ࠽? During execution. During compilation. While writing code. During interpretation. It must be a nice day ࠽? It is hot outside It is very hot outside It is cold outside About Contact Us Privacy Policy Cookie Policy Terms of Use Your Privacy Choices © 2024 SOPHIA Learning, LLC. SOPHIA is a registered trademark of SOPHIA Learning, LLC.
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