Python SQL Code Part1
Python SQL Code Part1
1. Count number of alphabets, digits, alphanumeric characters from the text file story.txt:
def count_characters(file_name):
content = file.read()
def count_words(file_name):
content = file.read()
words = content.split()
return len(words)
word_count = count_words('poem.txt')
3. Add even and odd elements of list separately and print the sum:
def sum_even_odd(lst):
4. Take input of name, age, salary, and designation and add it to a binary file record.dat. Fetch all records with age
import pickle
def fetch_records(file_name):
records = []
try:
while True:
record = pickle.load(file)
records.append(record)
except EOFError:
pass
return records
# Example usage
add_record('record.dat', 'John Doe', 36, 50000, 'Manager')
records = fetch_records('record.dat')
print(records)