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
1 month 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]1 month 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
Tanya wants to include a video with all its controls on her web page. The dimensions of the video are as follows:
Natasha_Volkova [1026]
I believe the correct answer is formats
4 0
18 days ago
Read 2 more answers
When handling project scope creep, which are two things that all parties involved need to be aware of?
zubka84 [1067]

Additional resources required for the projects

Added time necessary for the project

Clarification:

In any project management scenario, there will naturally be unexpected changes and additional needs, hence to successfully complete a project, one must allocate more time and resources. It is advisable that, based on the project specifics, the end user should maintain a sufficient buffer to accommodate any variations in human resources and the extra time necessary for project completion.

When planning the project, a consideration of extra time per each task is essential.

Every task within project management is categorized under distinct scopes of work.

3 0
1 month ago
Identify the four basic categories of hardware in a personal computer system
Harlamova29_29 [1022]
The four primary categories include the motherboard, CPU, graphics card, and RAM.
Please choose Brainliest! Thanks!:)
5 0
11 days ago
Need 2.5 Code Practice Answers
Natasha_Volkova [1026]

Answer:

import random

random.seed(1,10) # Note: seed takes one argument, so this line has an error

a = random.randint(1, 10)

b = random.randint(1, 10)

print("Calculate: " + str(a) + " X " + str(b) + "?")

ans = int(input("Your answer: "))

if ans == a * b:

print("Well done!")

else:

print("That's wrong!")

Explanation:

4 1
1 month ago
Read 2 more answers
A company moves a popular website to a new web host. Which of the following will change as a result?
8_murik_8 [964]
The root name server.
3 0
27 days ago
Other questions:
  • The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
    10·1 answer
  • A computer program is tested by 5 independent tests. If there is an error, these tests will discover it with probabilities 0.1,
    5·1 answer
  • A developer writes a trigger on the Account object on the before update event that increments a count field. A workflow rule als
    12·1 answer
  • Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values in an arr
    14·1 answer
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • Write a program in pascal to find the area of a circle
    14·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • An application specifies a requirement of 200 GB to host a database and other files. It also specifies that the storage environm
    12·1 answer
  • Drag each label to the correct location on the image.
    11·1 answer
  • The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the secon
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!