1answer.
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
ipn [44]
3 years 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:
lana66690 [7]3 years ago
8 0

Answer:

def get_word(sentence, n):

# Only proceed if n is positive

   if n > 0:

       words = sentence.split()

# Only proceed if n is not more than the number of words

       if n <= len(words):

           return words[n-1]

   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

Explanation:

Added parts are highlighted.

If n is greater than 0, split the given sentence using split method and set it to the words.

If n is not more than the number of words, return the (n-1)th index of the words. Since the index starts at 0, (n-1)th index corresponds to the nth word

You might be interested in
What export format is a great option for students that want to put their video into an online portfolio?
emmasim [6.3K]

Answer:

The answer is it depends on the videos that you will be using.

Explanation:

<em>If the student video is lenghty, the best format to use is MOV. (stands for MOVie by Quicktime) Because .mov files are designed for long, movie - like videos that doesn't take up much storage space but the quality is high. For streaming purposes, the best video format would be .WMV (or Windows Media Video). Although, quality of these videos are not that high, it is suitable for online quality as it loads faster. If the student would want his or her movie could be played in most devices, whether it is apple or android, the best format to use is .MP4 (stands for MPEG-4 or Moving Picture Experts Group). MP4 video files are often small and designed for portable devices. It is the most popular movie file type on the internet as it also supports streaming and subtitles. </em>

3 0
3 years ago
What is difference between RAM and ROM?
Lesechka [4]
Hi pupil here's your answer ::


________________________

RAM ::

● Data can be read and written on the RAM chip at any number of times.

● The operating system, application programs and the user data is stored in Ram only until the computer is powered on.

● Ram is a volatile memory that loses its contents when the computer is switched off.

● The size of RAM makes a difference in the processing, i.e. the bigger size of the RAM the greater is the speed of processing.

ROM ::

● Data can only be read from the ROM chip.

● Only system programs are stored in ROM. It can't be used to store user data and other programs.

● ROM is non volatile memory the data stored in ROM is permanent in nature.

● Size of the ROM has nothing to do with processing.


________________________

hope this helps. . . .
5 0
4 years ago
Which line of code outputs the decimal portion of a float stored in the variable x? print (x % 1000) print (x) O print (x / 1000
vlabodo [156]

print(x - int(x))

int(x) will round the float down to the nearest whole number x - int(x) subtracts that rounded value from the original float. This will leave the remaining decimal portion.

I hope this helps!

6 0
3 years ago
After a file downloads, you can do any of the following except
loris [4]
Change owner rights... I think you forgot to put the choices, I am taking a wild guess of what the answers could have been.
8 0
3 years ago
The language C was originally developed by​
nataly862011 [7]

Answer:

Dennis Ritchie

C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to make utilities running on Unix

3 0
3 years ago
Read 2 more answers
Other questions:
  • The first thing to do when your computer gives you a error message is
    7·2 answers
  • Can you give me a long list of old kid's cartoons
    8·1 answer
  • Describe network in terms of the class computer lab
    14·1 answer
  • An organization’s IRP prioritizes containment over eradication. An incident has been discovered where an attacker outside of the
    5·1 answer
  • Most colleges require blank years of foriegn language for admission
    9·1 answer
  • The feedforward part of the conversation should do all of the following except __________.a.identify the toneb.introduce the pur
    11·1 answer
  • Techniques that shape material without removing material.​
    6·1 answer
  • Do you think the current video game industry is likely to experience another “crash” (similar to the one in the 1980s) any time
    10·1 answer
  • What is a digital dashboard, and why are they becoming an increasingly popular tool?
    15·2 answers
  • Consider a student club or organization in which you are a
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!