2017-10-19 87 views
1

我在edX上面向初學者介紹Python的微軟課程,我在他們的第二個模塊中遇到問題,他們要求您創建向用戶添加「Doctor」標題的函數輸入名稱。在函數中定義用戶輸入時遇到的問題

這是他們所提供的建議:即需要一個參數名稱

  • 獲取用戶輸入的變量FULL_NAME
  • 呼叫使用FULL_NAME作爲參數
  • 打印功能

    • 定義功能make_doctor()返回值
    • 使用用戶輸入的full_name參數創建並調用make_doctor() - 然後輸出返回值

    這是我到目前爲止有:

    def make_doctor(name): 
    full_name = print("Doctor" + input().title()) 
    return full_name 
    
    print(name) 
    

    希望得到任何幫助。

  • 回答

    1

    這應該可以幫助您:

    def make_doctor(name): 
        return "Doctor" + name 
    
    
    full_name = input() 
    print(make_doctor(full_name)) 
    
    0
    def make_doctor(name): 
        # add the Doctor title to the name parameter 
        d_name = 'Doctor '+name 
        # print the return value 
        print(d_name) 
        return d_name 
    
    # get the user input for the variable full_name 
    full_name=input('Enter your full name: ') 
    # pass full_name as an argument to make_doctor function 
    doc = make_doctor(full_name) 
    # print return value 
    print(doc)