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
Savatey [412]
3 years ago
7

Write a Python function called readlinesmton that accepts the name of the file (i.e. filename), starting line number (i.e. m) an

d ending line number (i.e. n) as a parameter. The function then returns the contents from line number m to n (m < n). If m < 1 then start from line 1. Similarly, if n > number of lines the file, then stop at the last line in the file.
Computers and Technology
1 answer:
KatRina [158]3 years ago
5 0

Answer:

Following are the code to the given question:

def readlinesmton(filename, m ,n):#defining a method that holds three parameters

   f=open(filename, 'r')#defining f variable that holds open method

   l=f.readlines()#defining a variable l that readers input file

   e=len(l)#defining e variable lengths of the file  

   s=m#defining s variable that holds parameter value

   if(m<1):#Using if block that checks m is less than 1

       s=1#use s variable that holds a value that is 1

   if(n < e):#defining n variable that checks n less than e

       e=n #using e that holds n value

   for i in range(s-1, e, 1):#defining for loop that calculates lines  

       print(l[i])#prints lines

readlinesmton("input.txt", -1, 70)#Calling a method

Output:

Please find the ouput in the attached file.

Explanation:

In this code, a method "readlinesmton" is declared that takes three-parameter and inside the method, it uses the open method to open the file, read method to read the file, and len to calculate the length of the file and use the conditional statement to check the file inputs and use the loop to prints its values.    

You might be interested in
Which of the following is a key feature of a relational database?
Mekhanik [1.2K]

It uses primary keys and foreign keys as a means to provide efficient access to data and is supported directly in the database rather than maintained in the application code.

Explanation: Relational databases use an expressive query language, make efficient use of indexes within the database, ensure strong consistency, and fit well within an enterprise management system. Non-relational databases have a flexible data model, have high scalability, and performance, and have always-on global deployments.

3 0
1 year ago
Raid level 6 is basically the same as RAID level 5, but it adds a second set of parity bits for added fault tolerance and allows
Leviafan [203]

Answer:

True

Explanation:

3 0
3 years ago
Create a function that will perform linear interpolation from a set of measured data stored in a list or array. The function sho
wel

Answer:

This question is incomplete, here is the complete question:

Python

a) You should create a function that will perform linear interpolation from a set of measured data. The function should take as input a list of values at which samples were taken, and then another list giving the measurements (you can assume each measurement is a single value) at those values. It should also take in a query value, and should give the best estimate it can of the value at that query. Be sure to handle values that are outside of the range, by extrapolating. You should write a program that allows you to test your function by reading the lists from a file where each line of the file is a pair of numbers separated by spaces: the value where the sample was taken, and the measurement at that value. Your program should ask the user for the name of the file and for a query value. Important: The two lists will correspond to each other: i.e. for the i-th value in the first list, the measurement will be the i-th element of the second list (these are called parallel lists or arrays). But, you should not assume that the input values are in increasing/decreasing order. That is, the values in the first list can be in any random ordering, not necessarily from smallest to largest or largest to smallest. You will have to account for this in your program, and there is more than one way to do so. You should discuss what options you can think of to handle the data arriving in any order like that, and decide what you think the best option for handling it is.

Explanation:

from __future__ import division

from cStringIO import StringIO

import numpy as np

from scipy.interpolate import RectBivariateSpline

np.set_printoptions( 1, threshold=100, edgeitems=10, suppress=True )

   # a file inline, for testing --

myfile = StringIO( """

# T P1 P2 P3 P4

0,   80,100,150,200

75, 400,405,415,430

100, 450,456,467,483

150, 500,507,519,536

200, 550,558,571,589

""" )

   # file -> numpy array --

   # (all rows must have the same number of columns)

TPU = np.loadtxt( myfile, delimiter="," )

P = TPU[0,1:] # top row

T = TPU[ 1:,0] # left col

U = TPU[1:,1:] # 4 x 4, 400 .. 589

print "T:", T

print "P:", P

print "U:", U

interpolator = RectBivariateSpline( T, P, U, kx=1, ky=1 ) # 1 bilinear, 3 spline

   # try some t, p --

for t, p in (

   (75, 80),

   (75, 200),

   (87.5, 90),

   (200, 80),

   (200, 90),

   ):

   u = interpolator( t, p )

   print "t %5.1f p %5.1f -> u %5.1f" % (t, p, u)

8 0
3 years ago
Which of the following is not an advantage of concurrent design?
viva [34]

The answer I believe is B

7 0
3 years ago
Read 2 more answers
Write a C++ programthat returns the type of a triangle (scalene, equilateral,or
bixtya [17]

Answer:

#include<iostream>

using namespace std;

int main(){

   //initialize

   int a, b,c;

   //print the message

   cout<<"Enter the three sides of the triangle: "<<endl;

   //store in the variables

   cin>>a>>b>>c;

   //if-else statement for checking the conditions  

   if(a == b && b == c && a == c){

       cout<<"\nThe triangle is equilateral";

   }else if(a != b && b != c && a != c ){

       cout<<"\nThe triangle is scalene";

   }else{

       cout<<"\nThe triangle is isosceles";

   }

   return 0;

}

Explanation:

Create the main function and declare the three variables for the length of the sides of the triangle.

print the message on the screen for the user. Then the user enters the values and its store in the variables a, b, and c.

use the if-else statement for checking the conditions.

Equilateral triangle: all sides of the triangle are equal.

if condition true, print the equilateral triangle.

Scalene triangle: all sides of the triangle are not equal.

if condition true, print the Scalene triangle.

if both conditions is not true, then, the program moves to else part and print isosceles.

8 0
3 years ago
Other questions:
  • Which of the following correctly describes the function of an IP address?
    7·1 answer
  • What is one way to process your thoughts about the information you are reading?
    14·2 answers
  • The second row of letters on the keyboard is called the______ row
    14·2 answers
  • Show a single view of an object, but show it in a way that makes it look 3-D, as your eye would see it.
    10·1 answer
  • P3. In Section 4.2 , we noted that the maximum queuing delay is (n–1)D if the switching fabric is n times faster than the input
    8·1 answer
  • Henrietta, the owner of a very successful hotel chain in the Southeast, is exploring the possibility of expanding the chain into
    15·1 answer
  • If your computer won't connect to the internet, which of these is most likely to be the problem?
    8·1 answer
  • What does a computer need from people in order to solve problems effectively?
    9·1 answer
  • Answer this question for points lol
    7·2 answers
  • What keyword must be used on any method (function) on your class that is called from your main() method?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!