while True:
path = input('请上传文件:')
P = path.rfind('\\')
file = path[P+1:]
if file.endswith('jpg') or file.endswith('png') or file.endswith('bmp') or file.endswith('gif'):
print('图片上传成功!')
break
else:
print('上传的文件不是图片格式,请重新上传')
文件上传,只能上传图片(jpg,png,bmp,gif)while True: path = input('请上传文件:') P = path.rfind('\\') file = path[P+1:] if file.endswith('jpg') or file.endswith('png') or file.endswith('bmp') or file.endswith('gif'): print('图片上传成功!') break