Re:从非零开始的Python世界生活[7-用户输入和while循环]

'''
use int() to translate into 'int'
'''

'''
number = input("Enter a number, and i'll tell you it's even or odd: ")
if int(number)%2 == 0:
	print("Even: "+number+".")
else:
	print("Odd: "+number+".")
'''
'''
active = True
while active:
	message = input(prompt)
	if message!='q':
		print(message)
	else:
		active = False
'''
#use user's input to add the dic
responses = {}
polling_active = True

while polling_active:
	name = input("\nWhat's your name: ")
	#if name == 'q':
		#break;
	response = input("\nWhich mountain: ")
	#if response == 'q':
		#break;
	#responses['name'] = response
	responses[name] = response
	repeat  = input("\nWould you like another person (y/n): ")
	if repeat == 'n':
		polling_active = False
	else:
		polling_active = True
		
print("\n---Polling Results---")
for name,response in responses.items():
	print(name+":"+response+".")

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注


皖ICP备2021003932号
召唤伊斯特瓦尔