Hướng dẫn codingbat python string-1 answers - câu trả lời chuỗi mã hóa python chuỗi-1
Ngày đăng:
22/11/2022
Trả lời:
0
Lượt xem:
75
Tất cả các giải pháp đã được thử nghiệm thành công vào ngày 15 tháng 4 năm 2013. hello_name: def hello_name(name): return "Hello " + name + "!" make_abba: def make_abba(a, b): return a + b + b + a make_tags: def make_tags(tag, word): return "<" + tag + ">" + word + "" make_out_word: def make_out_word(out, word): return out[:2] + word + out[2:] extra_end: def extra_end(str): return str[-2:] * 3 Dấu hoa thị bị quá tải trong Python, như bạn thấy trong ví dụ này. Một giải pháp thay thế sẽ là kết hợp với các chương trình++, như bạn đã thấy nó trước đây. first_two: def first_two(str): if len(str) <= 2: return str return str[:2] first_half: def first_half(str): return str[:len(str)/2] without_end: def without_end(str): return str[1:-1] combo_string: def combo_string(a, b): if len(a) > len(b): return b + a + b return a + b + a non_start: def non_start(a, b): return a[1:] + b[1:] left2: def make_abba(a, b): return a + b + b + a0 DefCombo_String (A, B):
Cho 2 chuỗi, A và B, trả về một chuỗi của biểu mẫu ngắn+dài+ngắn,
|