Docsity

COMPUTER SCIENCE REVIEW (STRINGS) WITH RESEARCH, Exams of Nursing

Toggle sidebar
bg1
1 | P a g e
COMPUTER SCIENCE REVIEW (STRINGS) WITH
RESEARCHED QUESTIONS AND CORRECT ANSWERS ALL
GRADED A+
What function should be used in the blank to capitalize the first letter of the word stored in word?
first_char = word[0] word = first_char.______() + word[1:] -
CORRECT ANSWER>>> Upper
Which of the following choices will print AeCl? Assume the following variables have been defined.
first_name = "Alice"
last_name = "Carmichael" - CORRECT ANSWER>>> print first_name[0] + first_name[-1] +
last_name[0] + last_name[-1]
Which of the following expressions will result in "brown"?
Let sentence = "The brown lazy dog" - CORRECT ANSWER>>> print sentence[4:9]
Which of the following expressions will print "dog"?
Let sentence = "lazy dog" - CORRECT ANSWER>>> print sentence[5:]
Which of the following expressions will print "L"?
Let word = "PINEAPPLE" - CORRECT ANSWER>>> print word[-2]
pf3
pf4
pf5

Partial preview of the text

Download COMPUTER SCIENCE REVIEW (STRINGS) WITH RESEARCH and more Exams Nursing in PDF only on Docsity!

COMPUTER SCIENCE REVIEW (STRINGS) WITH

RESEARCHED QUESTIONS AND CORRECT ANSWERS ALL

GRADED A+

What function should be used in the blank to capitalize the first letter of the word stored in word? first_char = word[0] word = first_char.______() + word[1:] - CORRECT ANSWER>>> Upper Which of the following choices will print AeCl? Assume the following variables have been defined. first_name = "Alice" last_name = "Carmichael" - CORRECT ANSWER>>> print first_name[0] + first_name[-1] + last_name[0] + last_name[-1] Which of the following expressions will result in "brown"? Let sentence = "The brown lazy dog" - CORRECT ANSWER>>> print sentence[4:9] Which of the following expressions will print "dog"? Let sentence = "lazy dog" - CORRECT ANSWER>>> print sentence[5:] Which of the following expressions will print "L"? Let word = "PINEAPPLE" - CORRECT ANSWER>>> print word[-2]

Which of the following string operation is illegal? Assume that word = "music" - CORRECT ANSWER>>> word[0] = "M" Which of the following expressions will get the last character in a string? Assume that word is a string variable. I. word[0] II. word[-1] III. word[len(word)] IV. word[len(word)-1] - CORRECT ANSWER>>> II, IV What is the output of the following program? sentence = "the lazy dog" for letter in sentence: print letter + letter - CORRECT ANSWER>>> tt hh ee ll aa zz yy dd oo gg Whic h of the follo

in sente nce: print "Contains 'the'" Which of the functions below will return a string that is in alternating caps? For example, alt_case("sheep") should return "sHeEp". - CORRECT ANSWER>>> def alt_case(word): res = "" for i in range(len(word)): if i % 2 == 1: res = res + word[i].upper() else: res = res + word[i].lower() return res What is the value of pos after this function call? name = "Edsger Wybe Dijkstra" pos = name.find("W") - CORRECT ANSWER>>> 7 What is the value of pos after this function call? name = "Edsger Wybe Dijkstra" pos = name.find("Edsger") - CORRECT ANSWER>>> 0 What is the value of pos after this function call?

name = "Edsger Wybe Dijkstra" pos = name.find("z") - CORRECT ANSWER>>> - 1 What does this function do?

sentence: a string containing a sentence

char: a letter def

mystery(sentence, char): res = "" for letter in sentence: if letter == " ": res = res + char else: res = res + letter return res - CORRECT ANSWER>>> Returns the same sentence, but replaces every space with the letter char What does this function do?

address: string containing an email address

def mystery(address): if not ("@" in address): return "" address = address.strip() return address - CORRECT ANSWER>>> Checks to make sure the email address is valid by checking for '@' in the address. Returns the address without any leading or trailing whitespace. On which line does this program throw an error? word = "killer whale" pos = word.find(" ") word =

hidden_word = hidden_word + letter return hidden_word