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
ArbitrLikvidat [17]
3 years ago
7

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.
It should be like as this sample run follows.

Enter the input file name: quotes.xtxt
I cannot open the file quotes.xtxt - Please check the name and try again.
Enter the input file name: quotes.txt
The file has 16 lines.
Enter a line number [0 to quit]: 1
1: Hakuna Matata!
Enter a line number [0 to quit]: -1
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 16
16: Just keep swimming!
Enter a line number [0 to quit]: 17
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 5
5: It's kind of fun to do the impossible.
Enter a line number [0 to quit]: A
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: $
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: 4
4: To infinity and beyond!
Enter a line number [0 to quit]: 0
Computers and Technology
1 answer:
pickupchik [31]3 years ago
7 0

Answer:

Explanation:

iname=input("Enter the file name: ")

inputfile=open(iname,'r')

lines=[]

for line in inputfile:

lines.append(line)

inputfile.close()

print("The file has ",len(lines)," lines")

while True:

linenumber=int(input("Enter the line number or 0 to quit: "))

if linenumber==0:

break

elif linenumber > len(lines):

print("Error: line number must be less than ", len(lines))

else:

print(linenumber, " : ", lines[linenumber - 1])

You might be interested in
4. Write an appropriate comment for describ-
Mazyrski [523]

Answer:

AMAZING WORK YOUR SCORES WILL HELP YOU LATER ON

Explanation:

  1. THIS GIFT IS FOR MR REHMAN ITS A GRADE CALCULATOR
4 0
3 years ago
CLICK ME IF U DARE hehehe
amid [387]

Answer:

Display?

Explanation:

I am not sure that's the answer so....

6 0
3 years ago
Read 2 more answers
Write a code that takes numbers from the user as a list. (User can enter as many numbers as he wants). Then, find mean and stand
8090 [49]

nums = list(map(int, input().split()))

mean = sum(nums)/len(nums)

print("The mean is",mean)

values = 0

for x in nums:

   values += abs(x - mean)**2

print("The standard deviation is",(values / (len(nums)-1))**0.5)

I wrote my code in python 3.8. I hope this helps.

7 0
3 years ago
Complete the AscendingAndDescending application so that it asks a user to enter three integers. Display them in ascending and de
Andreas93 [3]

Answer:

Following are the solution to the given question:

import java.util.Scanner;//import package

public class AscendingAndDescending//defining a class AscendingAndDescending  

{

   public static void main(String[] args) //main method

   {

       int n1,n2,n3,min,max,m;

       Scanner in = new Scanner(System.in);//creating Scanner class object

       System.out.print("Enter an integer: ");//print message

       n1 = in.nextInt();//input value

       System.out.print("And another: ");//print message

       n2 = in.nextInt();//input value

       System.out.print("And just one more: ");//print message

       n3 = in.nextInt();//input value

       min = n1; //use min variable that holds value

       max = n1; //use mix variable that holds value

       if (n2 > max) max = n2;//use if to compare value and hols value in max variable

       if (n3 > max) max = n3;//use if to compare value and hols value in max variable

       if (n2 < min) min = n2;//use if to compare value and hols value in min variable

       if (n3 < min) min = n3;//use if to compare value and hols value in min variable

       m = (n1 + n2 + n3) - (min + max);//defining m variable that arrange value

       System.out.println("Ascending: " + min + " " + m + " " + max);//print Ascending order value

       System.out.println("Descending: " + max + " " + m + " " + min);//print Descending order value

   }

}

Output:

Enter an integer: 8

And another: 9

And just one more: 7

Ascending: 7 8 9

Descending: 9 8 7

Explanation:

In this program inside the main method three integer variable "n1,n2, and n3" is declared that inputs value from the user end and also defines three variable "min, max, and m" that uses the conditional statement that checks inputs value and assigns value according to the ascending and descending order and prints its values.

5 0
3 years ago
How can E-Commerce Portals ensure Security of online Transactions by Customers?
beks73 [17]
Ffkjlfdhaslkjfhlaksdfhlkajsdfh
6 0
3 years ago
Other questions:
  • The salesperson in a cell phone store is telling me that the phone I'm considering has 8GB of memory, which means I can save 10,
    13·1 answer
  • How can I sent a message?
    13·1 answer
  • Storing a value in a variable<br> Exponent<br> Variable<br> Assignment<br> Operator
    13·1 answer
  • PLEASE ANSWER THIS IM IN A QUIZ
    15·2 answers
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • The design of a blog refers to:
    10·1 answer
  • In which situation would saving a Word document as a PDF be most useful?
    9·2 answers
  • Can somebody do an Algorithm 2 for more?<br> (Python)
    15·1 answer
  • Five plus six is equal to?​
    10·2 answers
  • Whats the best way to make a video game?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!