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
mr Goodwill [35]
3 years ago
12

Write a Python program that takes a file name as input and generates the following output: File size in bytes and KBs Time the f

ile is created in human readable format (i.e., not a timestamp) Last time the file is accessed and modified, also in human readable format First character, middle character (2 character is even size), and last character Number of words in the file Number of lines in the file
Computers and Technology
1 answer:
Airida [17]3 years ago
8 0

Answer:

See explaination

Explanation:

import os

import time

from stat import *

file = input("Enter file name: ")

details = os.stat(file)#stores statistics about a file in a directory

print("File size: ", details[ST_SIZE])#retreiving size

print("File last accessed time: ", time.asctime(time.localtime(details[ST_ATIME])))#access time

print("File last modified time: ", time.asctime(time.localtime(details[ST_MTIME])))#modified time

print("File creation time: ", time.asctime(time.localtime(details[ST_CTIME])))#creation time

print("First character: ", file[0])

print("Middle character: ", file[len(file) // 2])

print("Last character: ", file[len(file) - 1])

num_words = 0

num_lines = 0

f=open(file, "r")

lines = f.readlines()

for line in lines:

num_lines = num_lines + 1

num_words = num_words + len(line.split())#add no. of words in that line

print("Number of lines: ", num_lines)

print("Number of words: ", num_words)

You might be interested in
A method for selecting multiple lines of text is to _______. select one:
Aliun [14]
I would probably say B even though the other methods might work as well
5 0
3 years ago
Which loan type requires you to make loan payments while you’re attending school?
Levart [38]
<span>A:Unsubsidized federal loan</span>
7 0
3 years ago
Write a program in pascal to solve a quadratic equation
GalinKa [24]
Program p1;
var a,b,c,d : integer; {i presume you give integer numbers for the values of a, b, c }
     x1, x2 : real;
begin 
write('a='); readln(a);
write('b='); readln(b);
write('c=');readln(c);
d:=b*b - 4*a*c
if a=0 then x1=x2= - c/b
          else
if d>0 then begin 
                 x1:=(-b+sqrt(d)) / (2*a);
                 x2:=(-b - sqrt(d))/(2*a);
                end;
          else if d=0 then x1=x2= - b /(2*a)
                           else write ("no specific solution because d<0");
writeln('x1=', x1);
writeln('x2=',x2);
readln;
end.
5 0
3 years ago
. What is piracy? ???????????????????​
Delicious77 [7]

Answer: a practice similar to piracy but in other contexts, especially hijacking.

"air piracy"

the unauthorized use or reproduction of another's work.

Explanation:

8 0
3 years ago
Define the term output devices​
expeople1 [14]

So a output device is anything that can output info from the computer so

we are read and understand it some are a printer monitor and soundboard

Hope this helped

-scav

6 0
2 years ago
Other questions:
  • PLEASE HELP ITS DRIVERS ED
    8·2 answers
  • The commands available here change depending on the activity taking place in the presentation window's main work area.
    15·2 answers
  • My mac book airs touch pad stopped working and i can't click. what do i do?
    5·2 answers
  • The ________ view in access looks similar to an excel spreadsheet.
    5·1 answer
  • ________ are the primary means of authentication for a user's computer and other networks and servers to which the user may have
    10·1 answer
  • In order to restrict editing to a document, a user will go to Review, , Restrict Editing, and will then select what kinds of edi
    12·1 answer
  • What is a photographic print made from a negative image?
    7·1 answer
  • Writing down your main ideas, subpoints, and supporting material, then using geometric shapes and arrows to indicate logical rel
    10·1 answer
  • Which artificial intelligence term is used to describe extracting information from unstructured text.
    15·1 answer
  • to provide for ecmascript compatibility in older browsers, you can use group of answer choices javascript shivs javascript shims
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!