Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take

1.Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'.

The input file can contain one or more sentences, or be a multiline list of words.

An example input file is shown below:

example.txt

the quick brown fox jumps over the lazy dog

An example of the program's output is shown below:

Enter the input file name: example.txt brown dog fox jumps lazy over quick the 

2.A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a file. The program should output the unique words and their frequencies in alphabetical order. Variations are to track sequences of two words and their frequencies, or n words and their frequencies.

Below is an example file along with the program input and output:

example.txt

I AM SAM I AM SAM SAM I AM

Enter the input file name: example.txt AM 3 I 3 SAM 3 

3.A positive integer greater than 1 is said to beprimeif it has no divisors other than 1 and itself. A positive integer greater than 1 iscompositeif it is not prime. Write a program that asks the user to enter an integer greater than 1, then displays all of the prime numbers that are less than or equal to the number entered (15 points).

The program should work as follows:

  • Once the user has entered a number, the program should populate a list with all of the integers from 2 up through the value entered.
  • The program should then use a loop to step through the list. The loop should pass each element to a function that displays the element whether it is a prime number.

4.Write a Python program to get the top three items price in a shop.(15 points)

Sample data: {'Apple': 0.50, 'Banana': 0.20, 'Mango': 0.99, 'Coconut': 2.99, 'Pineapple': 3.99}

Expected Output:

Pineapple 3.99

Coconut 2.99

Mango 0.99

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

2 Why real GDP is the appropriate measure of real economic activity

Answered: 1 week ago