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
Dmitrij [34]
3 years ago
14

Create a program that reads words.txt (link near top of our home page) in order to: determine the length of the longest word(s)

and output that length plus the first word of this length found. determine the length of the shortest word(s) and output that length plus the first word of this length found determine and output the average length of all the words in the list.
Computers and Technology
1 answer:
Alexeev081 [22]3 years ago
3 0
# In Python 3
# https://pastebin.com/fPSmmE5w

longest = [""]
shortest = None


with open("words.txt") as words:
   for line in words.readlines():
       for word in line.split():
           if len(word) > len(longest[0]):
               longest = [word]
           elif len(word) == len(longest[0]):
               longest.append(word)
           elif shortest is None or len(word) < len(shortest[0]):
               shortest = [word]
           elif len(word) == len(shortest[0]):
               shortest.append(word)


def format_printable(words):
   return ["{}: {}".format(len(word), word) for word in words]


print(
   "Longest:\n",
   "\n".join(format_printable(longest)),
   "\nShortest:\n",
   "\n".join(format_printable(shortest)),
)
You might be interested in
What is the argument in this function =AVERAGE(F3:F26)
monitta
The argument for the function would be answer "D".
5 0
2 years ago
Problem 1 Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according
DIA [1.3K]

Answer:

bill = float(input("Enter the bill amount: "))

rating = int(input("Choose a rating: 1 = Totally satisfied, 2 = Satisfied, 3 = Dissatisfied.: "))

if rating is 1:

   tip = bill * 0.2

elif rating is 2:

   tip = bill * 0.15

elif rating is 3:

   tip = bill * 0.1

print("The rating is: " + str(rating))

print("The tip is: $%.2f" % (tip))

Explanation:

*The code is in Python

- Ask the user for the <em>bill</em> and <em>rating</em>

- Depending on the <em>rating</em>, calculate the <em>tip</em> using <u>if else</u> statement i.e. If the rating is chosen as 1, calculate the tip by taking 20 percent of the bill.

- Print the <em>rating</em> and the <em>tip</em>

4 0
3 years ago
Dns uses udp instead of tcp. if a dns packet is lost, there is no automatic recovery. does this cause a problem, and if so, how
grandymaker [24]
Packet loss is typically resolved by time-outs and retries. For applications where a duplicate operation doesn't matter this is acceptable.
7 0
3 years ago
A Venn diagram is used to show...?<br> Plz help
11Alexandr11 [23.1K]
Venn diagrams are used to depict set intersections (denoted by an upside-down letter U)......
6 0
3 years ago
Read 2 more answers
Edward scissorhands Of course, Jim is the villain, but who or what is the antagonist in the film? Explain in detail.
Doss [256]
Jim is the main antagonist while Edward is the main protagonist of the movie.
8 0
2 years ago
Other questions:
  • Consider the cement used for the foundation; the bricks and timber used for the walls; and the shingles used for the roof. All o
    5·1 answer
  • The maximum number of colors that should be used on a slide is _____. 2 4 6 8
    5·1 answer
  • What is the best anime that you like the most (give me 3 plz)
    7·2 answers
  • About.com is considered a (an):
    6·1 answer
  • What are seven main internal parts of a computer
    7·2 answers
  • The M:N relationship between STUDENT and CLASS must be divided into two 1:M relationships through the use of the ENROLL entity;
    10·2 answers
  • Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1
    7·1 answer
  • Windows organises information on computer using a
    5·2 answers
  • Which magazine introduced the first microcomputer kit for the mits altair in its january 1975 issue?
    8·1 answer
  • What keyboard functions lets you delete words
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!