answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
V125BC
2 months ago
14

Using the "split" string method from the preceding lesson, complete the get_word function to return the {n}th word from a passed

sentence. For example, get_word("This is a lesson about lists", 4) should return "lesson", which is the 4th word in this sentence. Hint: remember that list indexes start at 0, not 1.
def get_word(sentence, n):
# Only proceed if n is positive
if n > 0:
words = ___
# Only proceed if n is not more than the number of words
if n <= len(words):
return(___)
return("")
print(get_word("This is a lesson about lists", 4)) # Should print: lesson
print(get_word("This is a lesson about lists", -4)) # Nothing
print(get_word("Now we are cooking!", 1)) # Should print: Now
print(get_word("Now we are cooking!", 5)) # Nothing
Computers and Technology
1 answer:
ivann1987 [1K]2 months ago
8 0

Answer:

def get_word(sentence, n):

# Only execute if n is a positive integer

   if n > 0:

       words = sentence.split()

# Ensure n does not exceed total words

       if n <= len(words):

           return words[n-1]

   return (" ")

print(get_word("This is a lesson about lists", 4)) # Expected output: lesson

print(get_word("This is a lesson about lists", -4)) # No output

print(get_word("Now we are cooking!", 1)) # Expected output: Now

print(get_word("Now we are cooking!", 5)) # No output

Explanation:

Highlights show added sections.

If n is greater than zero, the sentence is split into words using the split method.

If n is within the limit of the total number of words, the (n-1)th index will be returned, as indexing begins at 0, making (n-1) the correct reference for the nth word.

You might be interested in
Strlen("seven"); what is the output?
oksian1 [950]

Response:

Your answer is A, and I hope this information is useful.

4 0
2 months ago
A colleague asks you to research a CPU for a new server that will run Windows Server 2019. He explains the server roles that he
Rzqust [1037]

Response:

a

Explanation:

I’m just guessing

3 0
20 days ago
Create a conditional expression that evaluates to string "negative" if user_val is less than 0, and "non-negative" otherwise.
maria [1035]

Answer:

The revised code is as follows:

user_val = int(input())

cond_str = 'non-negative'  

if user_val < 0:

   cond_str = 'negative'  

print(user_val, 'is', cond_str)

Explanation:

This retrieves input for user_val

user_val = int(input())

This sets cond_str to 'non-negative'

cond_str = 'non-negative'

In cases where user_val is below 0

if user_val < 0:

Here cond_str changes to 'negative'

   cond_str = 'negative'  

This displays the intended output

print(user_val, 'is', cond_str)

4 0
2 months ago
A large organization is struggling to close the gaps in skill levels that exist between its employees and those from competing c
ivann1987 [1066]

Answer:

C.) by enabling employees to train and enhance skills for more advanced work

Explanation:

Hope this provides assistance!

3 0
1 month ago
A data analyst is using the Color tool in Tableau to apply a color scheme to a data visualization. They want the visualization t
Harlamova29_29 [1022]

Answer:

Color contrast refers to the disparity in brightness between text (or any foreground item) and the background it is set against.

Explanation:

In the realm of web accessibility, the extent to which one color contrasts with another dictates whether the information can be easily read by most individuals.

Contrast creates visual differences and helps elements stand out.

6 0
2 months ago
Other questions:
  • When you add a zero to the right of a decimal number, it multiplies its value by 10 (For example, "15" becomes "150"). What simi
    10·1 answer
  • A technician with a PC is using multiple applications while connected to the Internet. How is the PC able to keep track of the d
    8·2 answers
  • 3. Megan and her brother Marco have a side business where they shop at flea markets, garage sales, and estate
    9·1 answer
  • More Loops: All versions of foods.py in this section have avoided using for loops when printing to save space. Choose a version
    13·1 answer
  • On the planet Sigma, robots excavate chunks of a very precious cristaline. These chunks can be divided into smaller part only on
    15·1 answer
  • Language levels have a direct influence on _______________
    10·1 answer
  • _______________ is used by a hacker to mask intrusion and obtain administrator permissions to a computer.
    7·1 answer
  • According to the book, if your CPU usage levels are greater than ________ during most of your work session, a faster CPU can gre
    6·1 answer
  • Which of the following is true of how packets are sent through the internet?
    10·2 answers
  • A business wants to centralize its administrative tasks. At the same time, it wants the existing systems to manage and sustain t
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!