Concept of file path, absolute and relative file path. Program to accept string and display total number of alphabets.

5. Explain the concept of file path. Also discuss absolute and relative file path. Write a program to accept string and display total number of alphabets.

Answer:

File Paths in Python

Absolute Path

  • The complete path to a file from the root directory.
  • Example:
    C:\Users\UserName\Documents\file.txt

Relative Path

  • The path relative to the current working directory.
  • Example:
    Documents\file.txt

Python Program: Count Alphabets in a String

This program counts only the alphabet characters (A–Z, a–z) from the input.

text = input("Enter a string: ")
count = sum(1 for char in text if char.isalpha())
print("Total alphabets:", count)

Example:

Input: Hello123!
Output: Total alphabets: 5

Leave a Reply

Your email address will not be published. Required fields are marked *