Write a program that creates a file with a specific set of formatted values. o Ask the user for the name of the file and
● Write a program that creates a file with a specific set of formatted values. o Ask the user for the name of the file and create that file. o 20 lines of data will be written to the file with the following format: CCCCC III ccc FFFF.FF
Notes: CCCCC will be 5 uppercase letters, each of the 5 selected randomly. III is a random integer 0 and 999, right justified. ccc three lowercase letters, each selected randomly. FFFF.FF a random floating-point number between0 and 9999.99, limited to 2 decimal places. Each of the 4 values will be generated with a function, one function for each value. Example line in the text file: CPHEJ 1468 ksd 4356.82
# Python code to demonstrate the working of
# shuffle() and uniform() # importing "random" for random operations import random
# Initializing list li = [1, 4, 5, 10, 2]
# Printing list before shuffling print("The list before shuffling is : ", end="") for i in range(0, len(li)): print(li[i], end=" ") print("")
# using shuffle() to shuffle the list random.shuffle(li)
# Printing list after shuffling print("The list after shuffling is : ", end="") for i in range(0, len(li)): print(li[i], end=" ") print("")
# using uniform() to generate random floating number in range
# prints number between 5 and 16 print("The random floating point number between 5 and 10 is : ", end="") print(random.uniform(5, 10))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Python program that generates a file with 20 lines of formatted values as described python import ra...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started