Home > Blockchain >  How can I display or like show previous inputs or something like that
How can I display or like show previous inputs or something like that

Time:03-16

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"}

This line and redisplaying it at the user. After inputting all of the information how can it show in this format mine is not working I tried a lot

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")

CodePudding user response:

If you are getting inputs in different variables

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)

Mistakes you made

  1. variable names should not contain spaces
  2. While printing (referencing a variables) ,don't use ""
  3. should use comma or to add strings.

CodePudding user response:

I would also suggest the use of f-strings, here is how you could do it:

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']}")

CodePudding user response:

You can use f-strings to accomplish this. It puts the value of the variable:

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"]}")

CodePudding user response:

One more option is string.format():

print("So your name is {0} and you were born in {1}".format(info["Name:"], info["Birthdate:"]))
  • Related