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
WHAT DOES THE TRANSPORT LAYER USE TO MAKE SURE THAT A MESSAGE IS REASSWMBLED CORRECTLY ON THE RECEIVING DEVICES?
mrs_skeptik [129]
The answer is  sequence  number
6 0
3 years ago
using a timer to generate a random number, develop a program that displays random numbers between 1 and 47 (or whatever) for you
mestny [16]

Answer:

Explanation:

The following code is written in Python. It creates a variable that detects the current time. Then it loops through a range of numbers and chooses the last random number after 2 seconds. Finally, it prints that number to the screen. This function can be called countless times depending on the number of state lottery numbers needed.

import random

import time

start_time = time.time()

while time.time() - start_time < 2:

   lottery_number = random.randint(0, 48)

print(lottery_number)

3 0
3 years ago
The internet has provided great opportunities for fundraising. true/false
alekssr [168]
True, sites such as kickstarter and just giving are fantastic examples of such.
8 0
3 years ago
Assume that a single page of printed text requires 52 lines of text, and that each line of text averaged 80 characters. If each
zysi [14]

Answer:

4160000 bytes

Explanation:

One page = 52 lines of text

One line of text = 80 characters

=> One page = 80 x 52 = 4160 characters

Therefore, 500 pages of text will have 4160 x 500 characters = 2080000 characters.

Since 1 character takes up 2 bytes of computer memory, it impleies that a 500 page novel will take up 2080000 x 2 bytes = 4160000 bytes.

5 0
3 years ago
Assume X and Y are indepndent. Assume that X has mean 10 and standard deviation 8. Assume Y has mean 12 and standard deviation 6
Vitek1552 [10]

Answer:

\sigma_z = 10

Explanation:

Given

\bar x = 10

\sigma_x = 8

\bar y = 12

\sigma_y = 6

z = x + y

Required

\sigma_z

This is calculated as:

\sigma_z = \sqrt{Var(x) + Var(y)}

Calculate Var(x)

We have:

Var(x) = \sigma_x^2

Var(x) = 8^2

Var(x) = 64

Calculate Var(y)

We have:

Var(y) = \sigma_y^2

Var(y) = 6^2

Var(y) = 36

So, we have:

\sigma_z = \sqrt{Var(x) + Var(y)}

\sigma_z = \sqrt{64 + 36}

\sigma_z = \sqrt{100}

\sigma_z = 10

6 0
3 years ago
Other questions:
  • GoInternet, Inc., is an Internet-access service provider that is being forced to manage numerous unwanted e-mail messages from a
    10·1 answer
  • What is another name for a central processing unit? Computer Integrated circuit Microprocessor Transistor
    9·2 answers
  • How might an engineer test a computer chair for comfort?
    10·1 answer
  • Which of the following is a requirement for the Safety Data Sheet (SDS)?​
    5·1 answer
  • What is the main feature of Ethernet over Power?
    9·1 answer
  • Which processor family is most likely found on recent gaming laptops (Gaming laptops require a lot of computational power)?
    11·1 answer
  • I used the app and my answers were still wrong??????how
    8·2 answers
  • Can someone help me with this
    10·1 answer
  • Create a program that calculates the tip and total for a meal at a restaurant. Type the code into an IDLE IDE editor window and
    5·1 answer
  • Your first submission for the CIS 210 Course Project should include the following functionality: - Requests the user to input hi
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!