黑馬程序員python教程,8天python從入門到精通,學(xué)python看...


# 定義變量記錄錢包余額
money = 50
# 買了一個(gè)冰淇凌,花費(fèi)10元
money = money - 10
# 買了杯可樂,花費(fèi)5元
money = money - 5
# 錢包余額
print("錢包余額:", money)

name = "傳智播客"
stock_code = "003032"
stock_price = 19.99
stock_price_daily = 1.2
growth_days = 7
print(f"公司:{name},股票代碼{stock_code},當(dāng)前股價(jià){stock_price}")
result = stock_price * stock_price_daily ** growth_days
print("每日增長(zhǎng)系數(shù)是:%.2f,經(jīng)過%d天的增長(zhǎng)后,股價(jià)達(dá)到了:%.2f" % (stock_price_daily, growth_days, result))

user_name = input("請(qǐng)輸入用戶名")
user_type = input("請(qǐng)輸入用戶類型")
print(f"您好,尊敬的{user_name},您是我們尊貴的{user_type}用戶,歡迎光臨")

age = int(input("輸入年齡"))
if age >= 30:
??print("歡迎來到兒童游樂場(chǎng),兒童免費(fèi),成人收費(fèi)")
??print("您已成年,游玩需要補(bǔ)票10元")
print("祝您游玩愉快")

cm = int(input("請(qǐng)輸入你的身高"))
if cm >= 120:
??print("您的身高超出120cm,游玩需要購(gòu)票10元")
else:
??print("您的身高未超出120cm,可以免費(fèi)游玩")
print("祝您游玩愉快")

num = 10
if int(input("請(qǐng)輸入第一次猜想的數(shù)字:")) == num:
??print("猜錯(cuò)了")
elif int(input("請(qǐng)輸入第二次猜想的數(shù)字:")) == num:
??print("不對(duì),再猜一次")
elif int(input("請(qǐng)輸入第三次猜想的數(shù)字:")) == num:
??print("不對(duì),再猜最后一次")
elif int(input("請(qǐng)輸入第四次猜想的數(shù)字:")) == num:
??print("猜對(duì)了??")
else:
??print("Sorry,全部猜錯(cuò)了,我想的是:10")
print("玩的開心")

if guess_num == num:
??print("恭喜,第一次就猜中了")
else:
??if guess_num > num:
????print("你猜測(cè)的數(shù)字大了")
??else:
????print("你猜測(cè)的數(shù)字小了")
????guess_num = int(input("再次輸入你要猜測(cè)的數(shù)字:"))
????if guess_num == num:
??????print("恭喜,第二次猜中了")
????else:
??????if guess_num > num:
????????print("你猜測(cè)的數(shù)字大了")
??????else:
????????print("你猜測(cè)的數(shù)字小了")
??????guess_num = int(input("第三次輸入你要猜測(cè)的數(shù)字:"))
??????if guess_num == num:
????????print("恭喜,第三次猜中了")
??????else:
????????print("三次機(jī)會(huì)用完了,沒有猜中")

i = 1
sum = 0
while i <= 100:
??sum += i
??i += 1
??print(f"1到100累加的和是:{sum}")

i = 1
while i <= 10:
??j = 1
??while j <= i:
????k = i*j
????print('%d * %d = %d' % (j, i, k), end='\t')
????j += 1
??print()
??i += 1

name = "itheima is a brand of itcast"
count = 0
for x in name:
??if x == "a":
????count += 1
????print(f"{name}被統(tǒng)計(jì)的字符串中有{count}個(gè)a")

num = 10
count = 0
for x in range(num):
??if x % 2 == 0:
????count += 1
????print(f"{num}范圍,有{count}個(gè)偶數(shù)")

for i in range(1, 10):
??for j in range(1, i+1):
????print("%d*%d=%d" % (j, i, j*i), end="\t")
??print()

money = 10000
for i in range(1, 21):
??import random
??score = random.randint(1, 10)
??if score < 5:
????print(f"員工{i}績(jī)效分{score}, 不滿足,不發(fā)工資,下一位")
????continue
??if money >= 1000:
????money -= 1000
????print(f"員工{i},滿足條件發(fā)放工資1000,公司賬戶余額:{money}")
??else:
????print(f"余額不足,當(dāng)前余額{money}元,不足以發(fā)工資,不發(fā)了,下個(gè)月再來")
????break

def one_two():
??print("歡迎來到黑馬程序員!")
??print("請(qǐng)出示您的健康嗎以及72小時(shí)核酸證明")
one_two()

def add(x, y):
??print("歡迎來到黑馬程序員!請(qǐng)出示您的健康碼以及72小時(shí)核算證明,并配合測(cè)量體溫!")
??result = 37.5
??print(f"體溫測(cè)量中,您的體溫是:37.3度,體溫正常請(qǐng)進(jìn)")
??result = 39.5
??print(f"體溫測(cè)量中,您的體溫是:39.3度,需要隔離")
add(37.5, 39.5)

money = 5000000
name = None
name = input("請(qǐng)輸入姓名:")
def query(show_header):
??if show_header:
????print("---查詢余額---")
??print(f"{name},余額剩余{money}元")
def saving(num):
??global money
??money += num
??print("---存款---")
??print(f"{name},您好,您存款{num}元,成功")
??query(False)
def get_money(num):
??global money
??money -= money
??print("---取款---")
??print(f"{name},您好,您取款{num}元,成功")
??query(False)
def main():
??print("---主菜單---")
??print(f"{name},您好,歡迎來到黑馬銀行ATM,請(qǐng)選擇操作")
??print("查詢余額,\t輸入{1}")
??print("存款,\t\t輸入{2}")
??print("取款,\t\t輸入{3}")
??print("退出,\t\t輸入{4}")
??return input("請(qǐng)輸入您的選擇:")
while True:
??keyboard_input = main()
??if keyboard_input == "1":
????query(True)
????continue
??elif keyboard_input == "2":
????num = int(input("您想要存多少錢,請(qǐng)輸入:"))
????saving(num)
????continue
??elif keyboard_input == "3":
????num = int(input("您想要取多少錢,請(qǐng)輸入:"))
????saving(num)
????continue
??else:
????print("程序退出")
????break

age_list = [21, 25, 21, 23, 22, 20]
print(age_list)
age_list.append(31)
print(age_list)
age_list.extend([29, 33, 30])
print(age_list)
print(age_list[0])
print(age_list[-1])
print(age_list.index(31))

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
new_list = []
def while_list_func():
??index = 0
??while index < len(my_list):
????element = my_list[index]
????if element % 2 == 0:
??????new_list.append(element)
????index += 1
????print(f"通過while循環(huán),從列表{my_list}中取偶數(shù),組成新的列表:{new_list}")
while_list_func()
def for_list_func():
????for element in my_list:
??????if element % 2 == 0:
????????new_list.append(element)
????print(f"通過for循環(huán),從列表{my_list}中取偶數(shù),組成新的列表:{new_list}")
for_list_func()
new_list.clear()