包含有input函数的python文件需要在终端运行。
message = input("tell me somthing, I will repeat back to you:")
print(message)
input()函数进行字符输入。
prompt = "please input your name:"
prompt += "\nwhat is your first name!"
name = input(prompt)
print("hellow " + name + " !")
int()函数可以获取数值输入
height = input("How tall are you")
height = int(height)
if height >= 36:
print("\nYou are tall enought to ride!")
else:
print("\nYou can ride if you are a litter order!")
"%"是求余运算符号。
number = input("Enter a number:")
number = int(number)
if number %2 == 0 :
print("\nThe number " + str(number) + " is even.")
elif number%2 == 1:
print("\nThe number " + str(number) + " is odd.")
while循环举例:
current_number = 1
while current_number <= 5:
print(current_number)
current_number += 1
让用户选择什么时候推出。
prompt = "please input your name, I will repeat back to you:"
prompt += "\n Enter 'quit' to end the program. "
message = ""
while message != 'quit':
message = input(prompt)
if message != 'quit':
print(message)
在列表之间移动数据
unconfirmed_users = ['alice','brian','candace']
confirmed_users = []
while unconfirmed_users:
current_user = unconfirmed_users.pop() #每次从列表末尾删除未验证的客户
print("Verified Users:" + current_user.title())
confirmed_users.append(current_user)
print("following users have been confirmed:")
for confirmed_user in confirmed_users:
print(confirmed_user.title())
删除列表中的特定元素
pets = ['dog','cat','goldfish','dog','cat','rabbit']
print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)