0% found this document useful (0 votes)
12 views1 page

Class Notes IV

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Class Notes IV

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Aim: To create a menu-driven program to # 1) Check if lines have unique characters # 2) Count lines

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

You might also like