Class Notes IV
Class Notes IV
with unique characters Code: def create_file(): f = open("c.txt", "w") n = int(input("Enter no of lines:
")) for i in range(n): s = input("Enter Line: ") f.write(s + "\n") f.close() def unique_chars(): f =
open("c.txt") lines = f.readlines() f.close() unique_lines = [line for line in lines if len(set(line.strip())) ==
len(line.strip())] for line in unique_lines: print(line, end="") print(f"\nTotal lines with unique
characters: {len(unique_lines)}") def display_file(): f = open("c.txt") content = f.read() print(content)
f.close() create_file() while True: n = int(input("Enter 1 to display lines with unique characters, 2 to
display file content, 3 to exit: ")) if n == 1: unique_chars() elif n == 2: display_file() else: print("Thank
You") Break Output: Enter no of lines: 2 Enter Line: abcdef Enter Line: hello Enter 1 to display lines
with unique characters, 2 to display file content, 3 to exit: 1 abcdef Total lines with unique
characters: 1 Enter 1 to display lines with unique characters, 2 to display file content, 3 to exit: 3
Thank You