Computers and Technology
Computers and Technology, 25.02.2021 21:30, irene003

What is wrong with this piece of code? I am trying to create a list given specific strings and an input, then find the largest word and return/print it. def largest(words):

Length = 0
Word = ""

largest_word = ""
num_Words = len(words)

for x in range(0, num_Words, 1):
largest_word = words[x]
largest_length = len(largest_word)
if (largest_length >= Length):
largest_length = Length
largest_word = Word

return largest_word

user_pet = input("Enter a pet: ")
y = ["cat", "dog", "hamster", user_pet]
largest_petname = largest(y)
print(largest_petname)

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, Nicki3729
Exchanging which type of data uses the least bandwidth? music photographs video voice bandwidth- the amount of data that can be moved between two points in a set time period
Answers: 1
image
Computers and Technology, 22.06.2019 19:00, dadonelson2109
If your accelerator suddenly gets stuck what should you do
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, blake2001
Which of the following tasks is an audio technician most likely to perform while working on a nature documentary? (select all that apply). eliminating potentially distracting background noise adding sound effects making sure the lighting is adequate for a particular scene changing the narration to better match the mood of the documentary
Answers: 3
image
Computers and Technology, 24.06.2019 03:00, paguy12
What is one potential problem associated with an organization purchasing new technology early in its lifecycle
Answers: 1
Do you know the correct answer?
What is wrong with this piece of code? I am trying to create a list given specific strings and an in...

Questions in other subjects:

Konu
Social Studies, 21.08.2019 14:30
Konu
History, 21.08.2019 14:30