Python学习---用户输入和while循环

来源:互联网 发布:win10软件小助手 编辑:程序博客网 时间:2024/05/29 03:59

    今天看了python的用户输入和循环这部分,代码都挺简单,用法都很容易了理解。

#input()的工作原理message = input("Tell me something,and i will repeat it back to you: ")print(message)#input()的工作原理,接受一个参数,是要向客户显示的说明或提示,让用户知道该如何做prompt =  "if you tell us who you are,we can personalize the messages you see."prompt +=  "\nwhat is your first name?"name = input(prompt)print("\nhello," + name + "!")#使用int()来获取数值输入height = input("How tall are you, in inches? ")height = int(height)if height >= 36:print("\n You're tall enough to ride!")else:print("\nYou'll be able to ride when you're a little older.")#备注Python 2 中使用raw_input()获取用户输入,用法和input()一样#while循环current_number = 1while current_number <= 5:print(current_number)current_number += 1#首先,创建一个待验证用户列表#和一个用于存储已验证用户的空列表unconfirmed_users = ['alice','brian','candace']confirmed_users = []#验证每个用户,直到没有未验证用户为止#将每个经过验证的列表都移到已验证用户列表中while unconfirmed_users:current_user = unconfirmed_users.pop()print("Verifying user: " + current_user.title())confirmed_users.append(current_user)#显示所有已验证的用户print("\nThe followingusers have been confirmed:")for confirmed_user in confirmed_users:print(confirmed_user.title())