#獲取用戶輸入? input()? ? ()括號輸入 提示:用戶在輸入文本前看到的信息
#格式: 變量 = input('請輸入姓名')
message1 = input('please enter your name ')
print(message1)
print('------------')
#解決input()函數(shù)中提示過長惜傲,提前將文本存入一個變量
#示例? 該示例是一個多行字符串
letter = 'I want to know your age '
letter += '\nplease enter your age'
message2 = input(letter)
print(message2)
print('-----------')
#input()函數(shù)獲得用戶輸入類型都是String類型
#為了獲取int型數(shù)據(jù)逐哈,我們可以使用int(String),強制轉(zhuǎn)換促绵,等同于str(int)
message2 = int(message2)
if message2 > 18 :
? ? print("您已經(jīng)成年了")
elif message2 <= 18 :
? ? print("你是一個小朋友")
print('--------------')
#while 基本格式
#while 判斷語句 :
? ? # python語句
#直到判斷句結(jié)果為false缓艳,循環(huán)結(jié)束
letter1 = 3
while letter1 < 10 :
? ? letter1 += 4
? ? print(letter1)
print('--------------')
#使用while語句,用字典名或者列表名作為判斷條件時裙盾,只有列表(字典)內(nèi)元素為空才等同于False
dict = {1:11,2:22}
t = 1
while dict:
? ? del dict[t]
? ? t += 1
? ? print(dict)
#remove()清除列表中的特定值(第一次出現(xiàn)的)
#將remove()和while循環(huán)結(jié)合
list = ['cat','dog','pig','chick','hen','cat','elephant','cat']
while True :
? ? list.remove('cat')
? ? print(list)
? ? if 'cat' not in list:
? ? ? ? break
#方法2 使用set()函數(shù)加一次remove
#弊端:這樣其他重復(fù)的元素也會被清除
# list = set(list)
# list.remove('cat')
# print(list)