Quick actions

cmd+k|ctrl+k

Navigation

Languages

quangtranhong - pyfml - Exercise 3.3

Snippet info

Language

Python

Visibility

public

Author

quangtranhong

Created

2016-09-21T04:09:36Z

Updated

2016-09-21T04:11:33Z

# Bài 3.3
# -------
# Viết chương trình loại bỏ phần mở rộng của một tên file bất kỳ.
# Ví dụ::

# input = '....slsslslsls...sls'
# output = '....slsslslsls..'

# input = 'maria.ozawa.mp9'
# output = 'maria.ozawa'

input = 'Shigeo_Tokuda.jav'
print('Input: ', input)
idx = len(input) - 1

while idx > 0:
    if input[idx] != '.':
        idx -= 1
    else:
        break #thoát khỏi vòng lặp khi đã tìm thấy dấu '.' của phần extension

if idx == 0:
    print('Tên file không hợp lệ')
else:
    print('Output: ', input[:idx])
INFO