You can download this code by clicking the button below.
This code is now available for download.
Generates a random string of a specified length
Technology Stack : string, random
Code Type : String generation
Code Difficulty : Beginner
import string
import math
import random
import datetime
import json
import sys
import os
def generate_random_string(length):
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(length))
def calculate_circle_area(radius):
return math.pi * (radius ** 2)
def save_data_to_file(data, filename):
with open(filename, 'w') as file:
json.dump(data, file)
def read_data_from_file(filename):
with open(filename, 'r') as file:
return json.load(file)
def get_current_time():
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def delete_file(filename):
if os.path.exists(filename):
os.remove(filename)
def print_system_info():
info = {
'platform': sys.platform,
'version': sys.version,
'path': sys.path
}
return info