prompt = "If you tell us who you are, we can personalize the message you see." prompt += "\nWhat is your first name?" name = input(prompt) print(f"hello, {name}!")
输出结果为:
1 2 3
If you tell us who you are, we can personalize the message you see. What is your first name?zhang hello, zhang!
message = "" flag = True while flag: message = input("please input something:") if message != 'quit': print(f"your input the message is :{message}") else: flag = False
输出结果为:
1 2 3 4 5 6 7 8 9 10
please input something:hello your input the message is :hello
please input something:python your input the message is :python
please input something:world your input the message is :world
responses = {} polling_active = True#设置一个标志,指出调查是否继续 while polling_active: name = input("\nWhat is your name?") response = input("which mountain would you like to climb someday?") responses[name] = response repeat = input("would you like to let another person respond?(yes/no)") if repeat == 'no': polling_active = False print("\n---poll results---") for name, response in responses.items(): print(f"{name} would like to climb {response}")
输出结果为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
What is your name?zhangsan
which mountain would you like to climb someday?Deanli
would you like to let another person respond?(yes/no)yes
What is your name?lisi
which mountain would you like to climb someday?Devil`s Thumb
would you like to let another person respond?(yes/no)no
---poll results--- zhangsan would like to climb Deanli lisi would like to climb Devil`s Thumb
v1.5.2