Question

Using Python: Write a program that takes the size of a file (in bytes) as input...

Using Python: Write a program that takes the size of a file (in bytes) as input from the user, coverts it to the nearest whole number binary prefix (B for byte, KB for kilobyte, MB for megabyte, GB for gigabtye), rounded down. Any file sizes greater than 1024 GB should just be converted to GB.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
n = int(input("Enter total number of bytes: "))

if n >= 2 ** 30:
    print("{} bytes is {} GB.".format(n, n // (2 ** 30)))
elif n >= 2 ** 20:
    print("{} bytes is {} MB.".format(n, n // (2 ** 20)))
elif n >= 2 ** 10:
    print("{} bytes is {} KB.".format(n, n // (2 ** 10)))
else:
    print("{} bytes is {} Bytes.".format(n, n))
Add a comment
Know the answer?
Add Answer to:
Using Python: Write a program that takes the size of a file (in bytes) as input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python question: Write a program that takes in a positive integer as input, and outputs a...

    Python question: Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2

  • Task 1: Write a Python program that takes as input from the user the name of a file containing po...

    python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...

  • IN PYTHON Write a program that takes a user-input distance and speed and then calculates an...

    IN PYTHON Write a program that takes a user-input distance and speed and then calculates an ETA. Your program should work for ANY COMBINATION of distance and speed.

  • Write a Python program that reads from user the input file called data.txt that consists of...

    Write a Python program that reads from user the input file called data.txt that consists of a  keyword followed by a sequence of numbers separated by commas. If the keyword is UP, the  numbers are sorted in increasing order, if the key word is DOWN, the numbers are sorted in  decreasing order. The sorted sequence of numbers are saved in sorted.txt

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • 5.14 LAB: Convert to binary Write a program that takes in a positive integer as input,...

    5.14 LAB: Convert to binary Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the...

  • python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes...

    python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes an integer n as an argument. This function should display n to the user and prompt them to enter the number num that is the largest power of 2 less than or equal to n. Have your function return the user's input num (it will be used in the next problem) Problem 4 (Making a Game) Finally, create a main() function for your program....

  • Write a python program that does the following: takes as input from the user an English...

    Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...

  • Python Programing : Convert to binary - functions Write a program that takes in a positive...

    Python Programing : Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a...

  • Write a program using Python that loops through lines of a file, assuming each line of...

    Write a program using Python that loops through lines of a file, assuming each line of input will consist of just a single word (and a newline, of course). As it loops through each line, your program should print out any words that contain two vowels next to each other. The vowels do not have to be the same. You should create a test input file and make your script process it.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT