answer.
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
LiRa
1 month ago
6

Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename

and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number

Computers and Technology
2 answers:
amid [800]1 month ago
7 0

This code is in Python. I'm not certain what programming language you need.

Refer to the image:

Harlamova29_29 [932]1 month ago
7 0

Answer:

#section 1

filename = input('Enter file name: ')

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

   

   lines = []

   for line in file:

         lines.append(line.strip())

print('Total lines in the file:', len(lines))

#section 2

while True:

   line_number = int(input('Enter line number: '))

   if line_number == 0:

       break

   else:

       index = line_number - 1

       print(lines[index])

Explanation:

The programming language utilized is Python

# section 1

In this part, the program prompts the user for the file's name. It opens the file using a WITH statement, ensuring that it closes automatically when done.

An empty list is created to store the lines from the file.

A FOR loop is implemented to read through the file, adding each line to the list. The .strip() function removes any unwanted characters such as \t and \n from the text.

At the end of this section, the total line count is displayed using the len() function.

#section 2

<pIn this section, a WHILE loop is initiated to continue running until the user enters 0. The loop requests a line number from the user and then outputs that line's content to the screen.

I have included the result as an image.

You might be interested in
A 1.17 g sample of an alkane hydrocarbon gas occupies a volume of 674 mL at 28°C and 741 mmHg. Alkanes are known to have the gen
Natasha_Volkova [897]

Answer:

C3H8

Explanation:

Step 1:

Relevant details from the question are noted below:

Mass of the alkane is 1.17g

Volume (V) = 674 mL

Temperature (T) = 28°C

Pressure (P) = 741 mmHg.

Gas constant (R) = 0.08206 atm.L/Kmol

Step 2:

Convert to the appropriate units.

For Volume:

1000mL = 1L

So, 674mL = 674/1000 = 0.674L

For Temperature:

Temperature in Kelvin = Temperature in Celsius + 273

Temperature in Celsius = 28°C

Temperature in Kelvin = 28°C + 273 = 301K

For Pressure:

760mmHg = 1atm

So, 741 mmHg = 741/760 = 0.975atm

Step 3:

Calculate the moles of the alkane.

The moles of the alkane can be found using the ideal gas equation, presented below:

Volume (V) = 0.674L

Temperature (T) = 301K

Pressure (P) = 0.975atm

Gas constant (R) = 0.08206 atm.L/Kmol

Number of moles (n) =?

PV = nRT

n = PV /RT

n = (0.975 x 0.674)/(0.08206x301)

n = 0.0266 moles

Step 4:

Calculate the alkane’s molar mass.

Mass of alkane = 1.17g

Number of moles = 0.0266moles

Molar Mass =?

Number of moles = Mass/Molar Mass

Molar Mass = Mass/Number of moles

Molar Mass of alkane = 1.17/0.0266 = 44g/mol

Step 5:

Determine the molecular formula of the alkane.

This is based on:

The general formula for alkanes is CnH2n+2

To find the molecular formula, we start with n = 1, 2, 3, etc., until we find the molar mass of 44.

When n = 1

CnH2n+2 = CH4 = 12 + (4x1) = 16g/mol

When n = 2

CnH2n+2 = C2H6 = (12x2) + (6x1) = 30g/mol

When n = 3

CnH2n+2 = C3H8 = (12x3) + (8x1) = 44g/mol

It can be observed that for n equal to 3, the molar mass is 44g/mol.

Thus, the molecular formula of the alkane is C3H8.

7 0
29 days ago
When handling project scope creep, which are two things that all parties involved need to be aware of?
zubka84 [942]

Additional resources required for the projects

Added time necessary for the project

Clarification:

In any project management scenario, there will naturally be unexpected changes and additional needs, hence to successfully complete a project, one must allocate more time and resources. It is advisable that, based on the project specifics, the end user should maintain a sufficient buffer to accommodate any variations in human resources and the extra time necessary for project completion.

When planning the project, a consideration of extra time per each task is essential.

Every task within project management is categorized under distinct scopes of work.

3 0
27 days ago
Which kind of file would be hurt most by lossy compression algorithm
oksian1 [797]

Response: a file containing audio

Clarification:

8 0
10 days ago
Read 2 more answers
Input a number [1-50] representing the size of the shape and then a character [x,b,f] which represents the shape i.e. x-&gt;cros
Harlamova29_29 [932]

Response:

C++ code provided below with suitable annotations

Clarification:

pattern.cpp

#include<iostream>

using namespace std;

void printCross(int n)

{

int i,j,k;

if(n%2) //odd number of lines

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==i || j==(n-i+1))

cout<<j;

else

cout<<" ";

}

cout<<"\n";

}

}

else //even number of lines

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==i || j==(n-i+1))

{

cout<<" "<<j<<" ";

}

else

cout<<" ";

}

cout<<"\n";

}

}

void printForwardSlash(int n)

{

if(n%2)

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==n-i+1)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

else

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==(n-i+1))

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

}

void printBackwardSlash(int n)

{

if(n%2) // odd number of lines

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==i)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

else //even number of lines

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==i)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

}

int main()

{

int num;

char ch;

cout<<"Create a numberes shape that can be sized."<<endl;

cout<<"Input an integer [1,50] and a character [x,b,f]."<<endl;

cin>>num>>ch;

if(ch=='x' || ch=='X')

printCross(num);

else if(ch=='f' || ch=='F')

printForwardSlash(num);

else if(ch=='b' || ch=='B')

printBackwardSlash(num);

else

cout<<"\nWrong input"<<endl;

return 0;

}

4 0
20 days ago
Someone else can drive your car if _____.
8_murik_8 [892]

Answer:

C. you possess insurance documentation

Explanation:

Being a resident does not automatically grant permission to operate a vehicle. For instance, a person might have residency but might also have a suspended license, which means they are unable to drive.

Typically, insurance applies to the CAR rather than the individual. Therefore, the general guideline is:

A different person is permitted to drive your vehicle if you possess proof of insurance.

6 0
27 days ago
Read 2 more answers
Other questions:
  • 6. Write pseudo code that will perform the following. a) Read in 5 separate numbers. b) Calculate the average of the five number
    6·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • Light travels at 3 × 108 meters per second. A light-year is the distance a light beam travels in one year.Write a PYTHON program
    14·1 answer
  • Write a function solution that returns an arbitrary integer which is greater than n.
    13·1 answer
  • Edhesive 2.3 code practice question 1​
    11·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    7·1 answer
  • Choose the person responsible for each innovation.
    10·1 answer
  • Here is a super challenge for you if you feel up for it. (You will need to work this out in Excel.) In 2017 the Islamic month of
    11·1 answer
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
  • When long labels are required, which of these commands can you use to improve readability of a worksheet?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!