Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Chương trình Python đọc đầu vào từ console và chào hỏi


Đọc tên và họ từ console (mỗi giá trị một dòng), in lời chào: "Hello {first} {last}, you are welcome!". Sử dụng input() và str.format().

Ví dụ: nhập Ashish rồi Dutta → "Hello Ashish Dutta, you are welcome!".

Ví dụ mã nguồn

def solve():
    fn = input()
    ln = input()
    ret = "Hello {} {}, you are welcome!".format(fn, ln)
    return ret

print(solve())

Đầu vào / Đầu ra

Input:  Ashish Dutta (hai dòng)
Output: Hello Ashish Dutta, you are welcome!