info = {"Name:": "x", "Birthdate:": "x", "Gender:": "x", "Age:": "x", "Nationality:": "x", "Desired Course": "x", "Motto in life:": "x", "Dreams in life:": "x", "Favorite hobby:": "x"}
此行并在用戶處重新顯示。輸入所有資訊后如何以這種格式顯示我的不作業我嘗試了很多
列印(所以你的名字是“名字”,你出生在“生日”歲,你是“年齡”歲“國籍”“性別”,希望有一天成為“理想的課程”,你的座右銘是生活是“人生格言”和“人生夢想”,你最喜歡的愛好是“最喜歡的愛好”)
uj5u.com熱心網友回復:
如果您在不同的變數中獲得輸入
print("So your name is", name ,"and you were born in" ,Birthdate ," years old and you're a" ,Age ," year old " ,Nationality ,Gender," that wants to be a ,"Desired_course ," one day and your motto in life is ",Motto_in_life," and ",dreams_in_life" and your favorite hobby is ",Favorite_hobby)
你犯的錯誤
- 變數名不應包含空格
- 列印時(參考變數),不要使用“”
- 應使用逗號或 來添加字串。
uj5u.com熱心網友回復:
我還建議使用 f-strings,您可以這樣做:
info = {
"Name": "x",
"Birthdate": "x",
"Gender": "x",
"Age": "x",
"Nationality": "x",
"Desired Course": "x",
"Motto in life": "x",
"Dreams in life": "x",
"Favorite hobby": "x",
}
print(f"So your name is {info['Name']} and you were born in {info['Birthdate']} "
f"years old and you're a {info['Age']} year old {info['Nationality']} "
f"{info['Gender']} that wants to be a {info['Desired Course']} one day and your "
f"motto in life is {info['Motto in life']} and {info['Dreams in life']} and "
f"your favorite hobby is {info['Favorite hobby']}")
uj5u.com熱心網友回復:
您可以使用f-strings來完成此操作。它把變數的值:
print(f"So your name is {info["Name"]} and you were born in {info["Birthdate"]} years old and you are a {info["Age"]} year old {info["Nationality"]} {info["Gender"]} that wants to be a {info["Desired course"]} one day and your motto in life is {info["Motto in life"]} and {info["dreams in life"]} and your favorite hobby is {info["Favorite hobby"]}")
uj5u.com熱心網友回復:
另一種選擇是 string.format():
print("So your name is {0} and you were born in {1}".format(info["Name:"], info["Birthdate:"]))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/444681.html
上一篇:dict從鍵中獲取專案
下一篇:KIVY在外部條件下回圈遍歷影像
