Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CNM 140 Exam 2 with Questions and Answers, Exams of Computer Science

CNM 140 Exam 2 with Questions and Answers What placeholders are used when dealing with f-strings? a. ( ) b. [ ] c. { } d. : ANSWER✓✓ c. { } Use the price variable and f-string syntax to display the price with two decimals: price = 69 txt = f"The price is {__________} dollars" print(txt) a. :.2f b. price:.2f c. price * 100.00 d. price:2f ANSWER✓✓ b. price:.2f Use an if statement inside the f-string placeholders to return 'perfect' if the price is 100, and 'ok' if the price is not 100: price = 100 txt = f"It is {'perfect' ____________________________ 'ok'}" print(txt)

Typology: Exams

2024/2025

Available from 06/30/2025

school-inspector
school-inspector 🇺🇸

2

(1)

4.3K documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download CNM 140 Exam 2 with Questions and Answers and more Exams Computer Science in PDF only on Docsity!

CNM 140 Exam 2 with Questions and Answers What placeholders are used when dealing with f-strings? a0) d.: ANSWERVV ec. {} Use the price variable and f-string syntax to display the price with two decimals: price = 69 txt = f"The price is { } dollars" print(txt) an2t b. price:.2f e. price * 100.00 d. price:2f ANSWERVY b. price:.2f Use an if statement inside the f-string placeholders to return 'perfect' if the price is 100, and ‘ok’ if the price is not 100: price = 100 txt = f"It is {'perfect' ‘ok’}" print(txt) a. if price < 100 else b. if price > 100 else c. if price = 100 else d. if price == 100 else ANSWERV ¥ 4. if price = 100 else What would be the result onscreen of the following: price = 1000 txt = fThe price is {[price:,} dollars’ print a. The price is 1000 dollars b. The price is 1,000.00 dollars c. The price is 1000.00 dollars d. The price is 1,000 dollars ANSWERV ¥ d. The price is 1,000 dollars What character do you place at the start of a string to create an F-String? d. txt ANSWERVV c.f allows you to format selected parts of a string. a. Format() import mymodule print( ) a. list(mymodule) b. dir(mymodule) ec. len(mymodule) d. dir ANSWERV ¥ b. dir(mymodule) What is the correct syntax of importing only the person] dictionary of the "mymodule" module? mymodule import person! a. import b. from e. dir d. dict ANSWERV ¥ b. from True or False. There are modules built-in to Python. ANSWERV ¥ True Which is the correct syntax to print the age of person! imported from mymodule? a. print(mymodule["age"]) b. print(mymodule.person1["age"]) c. print (person ["age"]) d. print(mymodule.personl) ANSWER ¥ ec. print(person1["age"|) Python Lists can be used as arrays. What will be the result of the following code: fruits = ['apple’ , "banana’, 'cherrry'] print(fruits[0]) a. fruits b. apple c. cherry d. banana ANSWERV ¥ b. apple Python Lists can be used as arrays. What is a correct Python List method used to return the number of elements in a list? a. count() b. len) ¢. pop) d. length) ANSWERV ¥ b. len() Python Lists can be used as arrays. What will be the result of the following code: fruits = {'apple', ‘banana’, 'cherry'] print(len(fruits)) d. list ANSWERV ¥ b. library for x in range(3): print(x) What would be the result of the following code? a.012 b.0123 e123 d. No answer text provided, ANSWERV V a.012 Loop through the items in the fruits lists: fruits = ["apple", "banana", "cherry"] x in fruits: print(x) a. while b. if c. elsif d. for ANSWERV ¥ d. for Use the range function to loop through a code 6 times. for x in range( : print(x) a. for b.5 c.6 d. 1-6 ANSWERV ¥ c. 6 What would appear onscreen after the following code is run’? for x in range(1, 10, 1): print(x) a.12345678910 b.123456789 6012345678 d.0123456789ANSWERVYV b. 123456789 What would be onscreen when the following code is run? for x in range(1. 20, 5): print(x) a.05 1015 20 b.06 1121 c. 161116 a, elif b. return c. break d. continue ANS WERV v c. break In the example below, what would you put in line #5 to print the last line if the condition "while i < 6:" is false? i=l while i <6: print(i) it=1 print("i is no longer less than 6") a.ift b. else: c. elsif d. break: ANSWERY ¥ b. else: The while loop can execute a set of statements as long as the condition is a. true b. false c. greater than 0 d. greater than 1 ANSWERV ¥ a. true If you run the code below: i=l while i< 6: print(i) it=1 What will be the last number printed on screen? d.5 ANSWERV V 4.5 Given the code below: x=5 y=8 ifx>y: print(‘Hello') else: print(‘Welcome’) What will be the output on screen? d. != ANSWERVV¥ 4. != Complete the code below so that it will print "Yes" if'a is equal to b, otherwise print "No". print("Yes") print("No") a. clift b. else: c. elseif: d. if} ANSWERV ¥ b. else: Print "Hello" if a is equal to b, and ¢ is equal to d. ifa==b c==d: print("Hello") a. and b. or c. not d.—- ANSWERV ¥ a. and Print "Hello" if a is equal to b, or if c is equal to d. ifa==b c==d: print("ITello") a. and b. or c. not d. == ANSWERV ¥ b. or Python relies on to define scope in the code. Other programming languages often use curly-brackets for this purpose. a. If b. indentation ¢. spacing d. logical conditions ANSWERV ¥ b. indentation You can have if statements inside if statements, this is called if statements. a. coequal b. stacked ¢. conditional d. nested ANSWERV ¥ d. nested In Python 3.6 and newer, what is the name of the method used to ask for user input? a. user() b. prompl() Z=int(x) | int(y) print("Total family and friends: "| z) ‘The user enters in 5 for family and 10 for friends. What would be the output on the screen? a. Total family and friends 15 b. Total family and friends 510 c. Total family and friends 5 d. Error message. ANSWER V d. Error message. Given the following code: x = input("Enter number of family members: ") y = input("Enter number of friends: ") Z=int(x) | int(y_ print("Total family and friends: ") print(z) The user enters in 5 for family and 10 for friends. What would be the output on the screen? a. Total family and friends $10 b. Error message c. Total family and friends 15 d. Total family and friends on one line, and 15 on the line below ANSWERV ¥ d. Total family and friends on one line, and 15 on the line below