Write a program that prompts the user to enter a number and a file name. Then the program opens the specified text file then displays the number of unique words found in the file along with the first N words (specified by the user but limited from 1 to 10) sorted alphabetically. If the file contains less than the specified number of unique words, then display all unique words in the file sorted alphabetically. Hint: Store each word as an element of a set. Return the size of the set as the number of unique words. For the first N-words, convert the set to a list, sort it, then take a slice of the first N elements.

Answers

Answer 1

The Python program prompts for user input of a number and a file name, opens the specified file, counts the unique words, and displays the count along with the first N words sorted alphabetically.
Input validation is included to ensure the number is within the valid range.

Here's an example program in Python that prompts the user for a number and a file name, and then displays the number of unique words in the file along with the first N words (limited from 1 to 10) sorted alphabetically:

```python

def count_unique_words(filename):

   unique_words = set()

   with open(filename, 'r') as file:

       for line in file:

           words = line.split()

           unique_words.update(words)

   return unique_words

def display_words(unique_words, n):

   sorted_words = sorted(unique_words)

   print("Number of unique words:", len(sorted_words))

   print("First", n, "words:")

   print(sorted_words[:n])

def main():

   number = int(input("Enter a number (1-10): "))

   if number < 1 or number > 10:

       print("Invalid number. Please enter a number between 1 and 10.")

       return

   filename = input("Enter a file name: ")

   unique_words = count_unique_words(filename)

   display_words(unique_words, number)

# Run the program

main()

```

In this program, the `count_unique_words` function reads the specified file and uses a set to store the unique words. The `display_words` function sorts the unique words alphabetically and prints the count of unique words and the first N words.

The `main` function prompts the user for input and calls the other functions to perform the required operations. The program handles input validation to ensure the number is within the specified range.

You can run this program by saving it with a .py extension and executing it in a Python environment. Make sure to provide a valid file name and a number between 1 and 10 when prompted.

To learn more about Python program click here: brainly.com/question/27996357

#SPJ11


Related Questions

Which actions are available in the Trust Center? Check all that apply.
Enable macros.
Set privacy options.
Create mail merges.
Set trusted documents.
Approve trusted publishers.
Block users from receiving emails.

Answers

Answer: 1,2,4,5

Explanation:

bc

Where are the motors for the light year one located ???

Answers

Not sure honestly ...

How will an older browser display a blue box which has been made semi-transparent using CSS 3 opacity?

Answers

An older browser will display the blue box with full opacity, ignoring the CSS3 opacity property.

Cascading Style Sheets Level 3 (CSS3) is the iteration of the CSS standard used in the styling and formatting of Web pages. CSS3 incorporates the CSS2 standard with some changes and improvements.

The opacity property sets the opacity level for an element. CSS 3 opacity property is not supported by older browsers. When opacity is set to a value less than 1, modern browsers apply alpha blending to create a semi-transparent effect.

However, older browsers do not understand this property and treat it as if it doesn't exist. Consequently, the blue box will be displayed at full opacity, without any transparency effect.

When using CSS 3 opacity on an older browser, the blue box will not appear semi-transparent but will be fully opaque, as the opacity property is not recognized by older browser versions. It is important to consider browser compatibility when using CSS properties to ensure consistent rendering across different platforms and versions.

Learn more about CSS3 here:

brainly.com/question/32156289

#SPJ11

To answer the research question "How am I going to find the information I need on the tople?" the best thing Georgia should
do first is
get on her computer to search the topic
make a list of the books she could use.
ask her teacher for specific suggestions.
make a list of relevant sources to check out

Answers

Answer:

The correct option is D)  

Explanation:

To get information about a research topic the first thing to do is make a list of relevant sources.

Georgias sources would depend on the type of research she has been asked to conduct.

If it's primary research, she would collect information from:

Her own experienceHer own observationthe Information she gathers personally from other people

If it is  secondary research, she can look at

books (hard copy, e-copy)journals (online, offline)online (blogs, videos, websites etc)

Whilst looking online, it is important to stick to authoritative sources as it is possible for anyone to publish anything online.

Examples of reliable sources are:

Journals from Industry AssociationsBureaus of StatisticsGlobal Research CompaniesHigher Institutions e.t.c.

Cheers!

Answer:

D

Explanation:

Edge 2021

which of the following is true about dynamic programming? a. a dynamic programming solution for calculating the n th fibonacci number can be implemented with o(1) additional memory b. dynamic programming is mainly useful for problems with disjoint subproblems c. a bottom-up dp solution to a problem will always use the same amount of stack space as a top-down solution to the same problem d. a top-down dp solution to a problem will always calculate every single subprob- lem.

Answers

The correct statement about dynamic programming is option B: dynamic programming is mainly useful for problems with disjoint subproblems.

Dynamic programming is a problem-solving technique that involves breaking down a complex problem into smaller, overlapping subproblems and solving them independently. The solutions to these subproblems are stored in a table or array so that they can be reused as needed.

Option A is incorrect because a dynamic programming solution for calculating the nth Fibonacci number typically requires O(n) additional memory to store the intermediate results. The Fibonacci sequence has overlapping subproblems, and dynamic programming can efficiently solve it by avoiding redundant calculations.

Option B is true. Dynamic programming is particularly effective for problems with disjoint subproblems. Disjoint subproblems are subproblems that do not overlap or depend on each other. In such cases, dynamic programming can solve each subproblem independently and combine the solutions to obtain the final solution.

Option C is incorrect. The amount of stack space used by a dynamic programming solution depends on the specific implementation and the problem itself. It is not determined solely by whether it is a bottom-up or top-down approach.

Option D is also incorrect. A top-down dynamic programming solution can use memoization or caching techniques to avoid recalculating subproblems that have already been solved. This optimization ensures that not every single subproblem needs to be calculated, as the solution can be retrieved from the cache if it has been previously computed.

Learn more about dynamic programming

brainly.com/question/30885026

#SPJ11

Which three devices can perform both input and output operations

Answers

Answer:

router ,speaker, and nic card

Explanation:

The way a text looks or is designed is its _____
A. content
B. format
C. analysis
D. inference

I think the answer is B, format, please correct me if I’m wrong

Answers

Answer:

The correct answer is B.) So you are correct.

B is the correct answer


Bundlr is an example of gatekeeper technology.
Group startsTrue or False

Answers

Answer:

False

Explanation:

Write a C program to read temperature and display adequate information: Temperature <0-Freezing, Temperature 0-15 Very Cold weather, Temperature 15-25 Cold weather, Temperature 25-35 Normal in Temp, Temperature 35-45 Hot, Temperature >=45 Very Hot. Q2. WAP to find the factors of an input number. Q3. a. WAP to find the perimeter of a rectangle b. WAP to find the volume of a box (Ask dimensions from the user) Q4. WAP to print the number of digits in a number entered by the user.

Answers

1. To display the temperature in terms of adequate information, you can use the following C program. #include int main() { float temperature; printf("Enter the temperature: "); scanf("%f", &temperature); if(temperature < 0) printf("Freezing"); else if(temperature >= 0 && temperature < 15) printf("Very Cold Weather"); else if(temperature >= 15 && temperature < 25) printf("Cold Weather"); else if(temperature >= 25 && temperature < 35) printf("Normal in Temp"); else if(temperature >= 35 && temperature < 45) printf("Hot"); else printf("Very Hot"); return 0; }

2. To find the factors of an input number, you can use the following C program. #include int main() { int i, number; printf("Enter the number: "); scanf("%d", &number); printf("Factors of %d are: ", number); for(i=1; i<=number; ++i) { if(number%i == 0) printf("%d ", i); } return 0; }

3a. To find the perimeter of a rectangle, you can use the following C program. #include int main() { float length, width, perimeter; printf("Enter the length and width of rectangle: "); scanf("%f %f", &length, &width); perimeter = 2 * (length + width); printf("Perimeter of rectangle = %f units", perimeter); return 0; }

3b. To find the volume of a box, you can use the following C program. #include int main() { float length, width, height, volume; printf("Enter the length, width and height of the box: "); scanf("%f %f %f", &length, &width, &height); volume = length * width * height; printf("Volume of box = %f cubic units", volume); return 0; }

4. To print the number of digits in a number entered by the user, you can use the following C program. #include int main() { int number, count = 0; printf("Enter the number: "); scanf("%d", &number); while(number != 0) { number /= 10; ++count; } printf("Number of digits: %d", count); return 0; }

Learn more about program code at

https://brainly.com/question/33355523

#SPJ11

Which of the following can you use to judge source legitimacy?
A. The location the work was published in
B. How popular the author is
C. Date

Answers

Answer:

The answer is A

Explanation:

To judge a sources legitimacy is to find factual evidence on a page. Does the page use sources as well? Does the source come from a domain such as: .edu .gov etc.? Does the author show non opinions? If the answer to these questions is yes then your credible resource is accurate.

Well, I think it would depend... I would say it's B. since if it's a popular author, people must know that person as being a certain way, such as if they are credible, or they are a satire source. It could technically be date too, but I feel like it's more logically to go with B. the popularity of the author.

the linear program that results from dropping the integer requirements for the variables in an integer linear program is known as

Answers

The linear program that results from dropping the integer requirements for the variables in an integer linear program is known as a relaxation or a linear relaxation.

Integer linear programming (ILP) problems are optimization problems where some or all of the decision variables are required to take integer values. However, finding optimal solutions to ILP problems is generally computationally hard. Linear programming (LP) problems, on the other hand, are optimization problems where all the decision variables are allowed to take any real value. Solving an LP problem is relatively easier than solving an ILP problem.

In the relaxation process, the constraint that requires the variables to be integers is relaxed, allowing the variables to take any real value. This process transforms the original ILP problem into a relaxed LP problem that can be solved using standard LP techniques. The solution obtained from the relaxation process is an upper bound on the optimal solution to the original ILP problem.

In practice, the relaxation process is often used as a first step in solving an ILP problem. If the optimal solution to the relaxed LP problem is an integer solution, then this solution is also optimal for the original ILP problem. If not, then additional techniques such as branch and bound or cutting planes are used to solve the original ILP problem.

To know more about  linear program click this link -

brainly.com/question/30763902

#SPJ11

When an object is acted on by unbalanced forces, the object will always

Answers

Answer:

If an object has a net force acting on it, it will accelerate. The object will speed up, slow down or change direction. An unbalanced force (net force) acting on an object changes its speed and/or direction of motion. An unbalanced force is an unopposed force that causes a change in motion.

Explanation:

write a python program to initialize the value of two variables then find sum

Answers

Answer:

JavaScript:

Let x = 10

Let y = 10

Console.log(x + y)

//outputs 20

C++:

Let x = 10

Let y = 10

The file is Math.cpp so,

std::cout << "" + y + "" + x

g++ Math.cpp -o Maths

./Maths

//Outputs 20

Answer:

#Ask the user for a number

a = int(input("Enter a number: "))

#Ask the user for a number

b = int(input("Enter a number: "))

#Calculate the sum of a and b

sum = a + b

#print the ouput

print(str(a) + " + " + str(b) + " = " + str(sum))

what is cyber safety?

Answers

Answer: Cyber safety is a process that protects computers and networks. The cyber world is a dangerous place without security and protection.

Explanation: Hope this helps!

Some people worry that there won’t be enough jobs in the future because computers will be able to do everything better than people can. Do you think that will happen? Why or why not? pls explain

Answers

Answer: I think it will because there are cars that Drive by there self

Explanation:

What is the use of Ellipse Tool in photoshop

What is the use of Ellipse Tool in photoshop

Answers

The Ellipse Tool creates elliptical shapes and paths (shape outlines) it’s also used for elliptical, including circular, selections. You can easily select objects such as clocks, balls, and full moons by using this tool. There is a keyboard shortcut where if you see the elliptical tool in the tool box, you can press M on the keyboard, if you see a rectangular tool, press shift + M together on the keyboard. Hope that helped!

Type the correct answer in the box. Spell all words correctly.
How can aspiring illustrators hone their skills?
Aspiring illustrators can hone their talent and skills using _____________ software.
Help asap
100 POINTS

Answers

Answer:

Aspiring illustrators can hone their talent and skills using Adobe Illustrator software.

Explanation:

By using this software we enroll graphics for out Television.Computer etc ..

what do you mean by formatting the document?​

Answers

Answer: See explanation

Explanation:

Document formatting simply refers to how a document is laid out. It involves specifications about the look of a document.

During formatting of a document, some of the things done include alignment, margin, font, color, font size, indentation etc. All three eventually gives the document its look.

When you instruct a computer or mobile device to run an application, the computer or mobile device answer its software, which means the application is copied from storage to memory?

Answers

I believe loads

not for sure what the question is

How do i fix this? ((My computer is on))

How do i fix this? ((My computer is on))

Answers

Answer:

the picture is not clear. there could be many reasons of why this is happening. has your computer had any physical damage recently?

Answer:your computer had a Damage by u get it 101 Battery

and if u want to fix it go to laptop shop and tells him to fix this laptop

Explanation:

You must give careful consideration before adding text to a placeholder because once text has been entered into a placeholder, the placeholder cannot be deleted. Responses true true false false

Answers

The statement "once text has been entered into a placeholder, the placeholder cannot be deleted" is false. In most presentation software, including Microsoft PowerPoint and Slides, it is possible to delete a placeholder after text has been added to it.

However, it is still important to give careful consideration before adding text to a placeholder. Once text has been added to a placeholder, it can be difficult to move or resize the placeholder without affecting the text. This can make it challenging to adjust the layout and design of a slide or presentation.Additionally, adding text to a placeholder without careful consideration can lead to cluttered and confusing slides. It's important to think about the purpose and audience of the presentation, and ensure that the text added to a placeholder is relevant and contributes to the overall message of the presentation. while it is possible to delete a placeholder after text has been added to it, it's still important to approach placeholder use with consideration and intention to ensure effective and visually pleasing presentations.

To learn more about software click the link below:

brainly.com/question/985406

#SPJ4

Amara created a workbook to track the number of minutes she reads each week. Each day, she entered the number of minutes into the workbook. Identify the types of data in the workbook using the drop-down menus. 25: 105: Wed:

Answers

Answer:

25: Value

105:Formula

Wed: Label

Explanation:

Answer:

C- Value

A- Formula

B- Label

Explanation:

Which word should a programmer use to describe what should happen when the condition of an if statement is NOT met?

A.
iterative

B.
when

C.
else

D.
also

Answers

The word  that should a programmer use to describe what should happen when the condition of an if statement is NOT met is option C. else.

Why are conditional statements used in programming?

When a condition is true or false, a conditional statement instructs a program to take a certain action. If-then or if-then-else statements are frequently used to represent it. The preceding example is a block of code that employs a "if/then" conditional statement.

Therefore, the else statement is used, "to indicate what should happen when the condition of an if statement is not fulfilled," is the proper response since the otherwise statement is typically used when computations are still necessary when a condition in an if and else-if statement is not met.

Learn more about programmer from

https://brainly.com/question/22654163

#SPJ1

Computer engineering is a career that......

Answers

Answer:

Computer engineering is a career that works on the development and research of new technology-related things.

Explanation:

hãy mô tả thuật toán cho bài toán sau: Cho N và dãy a1, a2,.. an. Hãy cho biết số âm trong dãy số đó.

Answers

Answer:

I can't understand you lol your so mudafaka

4.2 q1: which of the following is not an algorithm?a.a recipe.b.operating instructions.c.textbook index.d.shampoo instructions (lather, rinse, repeat).

Answers

Shampoo instructions lather, rinse, repeat. shampoo instructions do not have a clear and specific sequence of steps that are universally agreed upon.

An algorithm is a precise set of instructions that can be followed to solve a problem or complete a task. While shampoo instructions do provide a general idea of what needs to be done, they do not provide a specific sequence of steps that must be followed. Therefore, they cannot be considered as an algorithm. I hope this explanation helps .

An algorithm is a step-by-step procedure or a set of instructions to solve a particular problem or perform a task. Let's analyze each option. A recipe This is an algorithm as it provides a sequence of steps to prepare a dish. Operating instructions ,These are also algorithms since they give step-by-step guidance on how to use a device. Textbook index This is not an algorithm, as it is simply a reference tool for finding information within a book, rather than a step-by-step procedure. Shampoo instructions lather, rinse, repeat This is an algorithm, as it outlines a sequence of steps to wash your hair.
To know more about instructions lather visit :

https://brainly.com/question/14446782

#SPJ11

Often presented visually on an executive dashboard, what type of report focuses attention on business processes whose performance falls outside of the tolerance ranges defined a kpi metric?.

Answers

The answer to the assertion whose performance falls outside of the tolerance ranges defined a kpi metric made is an exception.

Does metric correspond to KPI?

Metrics are often operational or tactical, whereas KPIs are strategic. Metrics are less complex indications that are unique to a department, whereas KPIs can be reviewed by many departments that are working toward the same goal. KPIs assist you in making strategic decisions, whilst metrics give you a perspective on your business activity.

What is a KPI measurement?

The metrics you use to assess tasks, goals, or objectives that are essential to your business are known as key performance indicators, or KPIs. The use of the word "key" in the sentence denotes that the words have a unique or important meaning. KPIs serve as measurable benchmarks in relation to established targets.

To know more about KPI metric visit:

brainly.com/question/28455765

#SPJ4

9.To have your macros available when creating additional workbooks, you should consider
a. creating a macros workbook.
b. writing your macros directly in VBA.
c. storing all of your workbooks on a shared network drive.
d. leaving open all the workbooks containing macros.

Answers

To have your macros available when creating additional workbooks, you should consider the option a. creating a macros workbook.

A macros workbook, also known as a Personal Macro Workbook (PMW), is a central repository for storing your commonly used macros. By storing macros in the PMW, you ensure that they are accessible whenever you create or open other workbooks in Excel. Writing your macros directly in VBA (Visual Basic for Applications) is a powerful method, but it does not guarantee their availability across all workbooks. Storing workbooks on a shared network drive only affects their location and accessibility for multiple users but doesn't affect macros availability.

Leaving open all workbooks containing macros is not practical, as it can clutter your workspace and cause performance issues. Creating a macros workbook simplifies your workflow and provides a seamless experience. When you store your macros in the PMW, they become available in the background every time you open Excel. This allows you to execute your macros quickly and efficiently, regardless of the workbook you are working on.

In summary, to ensure that your macros are available when creating additional workbooks, create a Personal Macro Workbook to store them. This method offers a convenient, efficient, and organized way to manage and access your macros across different workbooks in Excel. Therefore, the correct answer is option a.

know more about macros workbook here:

https://brainly.com/question/31689399

#SPJ11

Choose the correct term to complete the sentence. A _______ has functions that allow you to appendleft and popleft.

A
deque
B
amplified list
C
list
D
deck

Answers

Answer:

A. Deque according to text books

Answer:

deque

Explanation:

Edge 2020

Aside from ms excel, what other spreadsheet programs are used today find out what these are and describe their similarities and differences with excel.

Answers

Answer:

Libre office, Gogle sheet

Explanation:

Spreadsheets programs are immensely useful to organizations as they are used for entering data and making several analytical calculations and

decision. The most popular spreadsheet program is Excel which is from Microsoft. However, other spreadsheet programs have been developed. The most common of those are ;Libre office and Gogle sheets.

Similarities between the programs include :

Most have similar functionality and aim, which is to perform and make analytics easy.

The differences may include ; Microsoft excel is credited to Microsoft corporation and the program which forms part of Microsoft office suite including Word , power point, outlook e. T c. Microsoft excel is this not a free program.

Gogle sheets is from Gogle.

Libre office is open source and hence it is free

Other Questions
Which process would be least affected if a root cell experienced a reduction in atp supply? Becky wants to have $1,000,000 when she retires. If she deposits $25,000 in the bank today and earns 8% compounded annually number of years 47.93.Given the above information, but Becky has learned about a new investment that will earn her 12% compounded annually instead of 8%. How many years will it take her to reach her investment goals? Multiply (x + y)(x + y + z).Question 8 options:x2 + y2 + 2yx + xz + yzz2 + y2 + 3yz + xy + yzx2 y2 + 2yx xz + yzz2 + x2 2yx + xz + yz At a store, the cost of 5 pounds of carrots is $3.35. Which statement about the cost per pound of carrots is true?A. Subtract the total cost from the number of pounds to get $1.65 per pound.B. Multiply the total cost by the number of pounds to get $16.75 per pound.C. Divide the number of pounds by the total cost to get $1.49 per pound.D. Divide the total cost by the number of pounds to get $0.67 per pound. Describe the period 1945-1980 from the perspective of the individual you chose to interview. Recent research indicates that inflation performance (low inflation) has been found to be best in countries withA) a policy of always keeping interest rates lowB) money financing of budget deficitsC) political control of monetary policyD) the most independent central banks Determine the missing digit (denoted with*) for the American Express Traveler's Check identification number 783920*814 a) 3 b) 2 c) 6 d) 9 3[tex]3\frac{1}{3} (-2\frac{1}{4} )+1\frac{5}{6}[/tex] what is the minimum number of participants that must receive the ``global commit'' message to allow the participants to complete the transaction without waiting for the master to recover? PLEASE HELP ASAPusing descartes rule of signsH(x)=4x^4-5x^3+2x^2-x+5 which is closely related to a whale? a shark, a toad, an alligator, a penguin or a bat? What two numbers when multiplied equil 12 and when added equil 4 Please help me asap due at 5:00 A stone is thrown horizontally at 30.0 m/s from the top of a very tall clifl. (a) Calculate its borzoetal peasation and vertical poution at 2 s intervals for the first 10.0s. (b) Plot your positions f use a case 1-case 2 ratio box to solve this problem: one hundred inches equals 254 centimetres. how many centimetres equals 250 inches? if you dont know what a case 1-case 2 ratio box is, search it up the gutierrez-magee expedition led to _________ Plz answer quickly -3 = z - 8 Who has the most power in the House of Representatives? efficacy and safety of tisagenlecleucel in adult patients with relapsed/refractory follicular lymphoma: interim analysis of the phase 2 elara trial I should probably not paint the walls of my apartment because O I have an absolute advantage in painting my walls relative to a painting service. O I have a comparative advantage in painting my walls relative to a painting service. O my opportunity cost of painting my walls is higher than the cost of paying someone to do it for me. O I might fall from the ladder.