具体的看代码方式参考第一篇文章
一天PYTHON速成(PART 01)_m0_57628341的博客-优快云博客
同样的贴第二部分
#########第二篇文章
#
##讲解BREAK的一些用法,当然结合之前的DEBUG就更好了
# friends = ["A", "B", "C", "D", "E", "F"]
# best_friend = "C"
# for friend in friends :
# if friend == best_friend:
# print(f"{best_friend} is in the list")
# break
# else:
# print(f"This is my {friend}")
#
#
##一个小小的测试程序 非常有意思,其实很值得学习
# sum_budget = 100
# sandwich_price = 5
# count_number =0
# for s in range(20) :
# sum_budget = sum_budget - sandwich_price
#
# sum_budget -= sandwich_price 其实这句话和上面那句是相同的,是PYTHON特有的减量
#
# count_number = count_number +sandwich_price
# if sum_budget == 0 :
# print("you have no more money")
# break
# else :
# print(f"you have used {count_number} $")
# print("i like sandwich !")
#
#
###就是说啥呢 -=是一个循环里持续的减量;;;;而+=固然就是循环中持续的一个加量
#
#
##while循环 相较于FOR循环,更加纠结于True和False的一个返回值
##这个和C++中的WHILE也是有很大的一个区别,我觉得很值得区分
# sum_budget = 100
# sandwich_price = 5
# count_number =0
# while sum_budget > 0 : 这里有一个有意思的,由于我们知道WHILE是一个基于判断TRUE和FALSE的语言
# sum_budget -= sandwich_price 因此,无限循环的表达方式和C++类似
# count_number += sandwich_price 众所周知C++中为while(1)
# print(f"you have used {count_number} $") 而Python中就变成了while 1==1;或者while True
# print("you have no money") 这就显得特别有趣了,哈哈哈
#
#
##上文注释中的小例子
#
# budget = 100
# count = 0
# golden =1
# while True:
# print(f"you have used {count} $")
# count += golden
# budget -= golden
# if budget == 0 :
# break
#
# print("we have no money")
#
#
##又一个小例子的进行,电梯问题
#
#这道题很有意思,特别强调了一点,就是我们输入的input是默认的STRING,但是当你的条件条件选项中存在不是String类型的类时,就需要进行一次强行的转换
# while True :
# answer = input("which floor you want me to take you ?")
# if answer == "out" :
# print("Exiting ...")
# break
# else:
# answer_floor =int(answer)
# if answer_floor > 0 and answer_floor <= 20 :
# print(f"You are on floor number {answer_floor}")
# else:
# print("we don't have the floor ....")
#
#
##写一个函数
#
#最简单的版本
# def special_count() :
# for i in range(1, 11, 1) :
# print(f"counting .. {i}")
#
# special_count()
#
#这个版本和C++中的差不多理解,只不过形式不一样罢了
# def special_count(stop_count, divien) :
# for i in range(1,stop_count+1,divien) :
# print(f"counting .. {i}")
#
# special_count(10, 2)
# special_count(20,5)
# special_count(5,1)
#
#写一个勾股定理的函数
# def Gougu_defination(a, b, c) :
# num_ab = a ** 2 +b ** 2
# num_c = c ** 2
# if num_ab == num_c :
# print(f"the combination of : {a},{b},{c} support pyth law")
# else :
# print("that is worry")
#
#
# Gougu_defination(3, 4, 5)
# Gougu_defination(4, 4, 7)
#
#
##讲函数中的RETURN值的问题
# def square_mynum(num) :
# return num ** 2 这里非常又意思,因为和C++不同,C语言中,实在函数的括号内加上VOID来实现无返回值的
# //rutuen none 但是在这里的话不同的地方在于,你是在函数中去告诉函数,返回值到底是啥的
# //print .. (不被允许) 当然更有意思的在于,你也可以告诉它,不返回//不过由此而来的代价是,当你存在返回值的时候,你的其他执行语句就不再被执行了
# result = square_mynum(2)
# print(result)
#
#
##信用卡挑战 我总发现别人想的方法比我想象的更加简单
#第一种:简单的
# def hide_card(num) :
# last_four_num = num[-4 :]
# return f'**** **** **** **** {last_four_num}'
# my_card = hide_card('1234567890123456789')
# print(my_card)
#
#
#第二种版本,这个会难很多,最主要的问题,我觉得还是解决函数类的问题,如何保证类相同,才是最难的
# def hide_card(num) :
# cardlist = []
# for cnum in num :
# last_num = cnum[-4:]
# fomatted_cnum = f'**** **** **** {last_num}'
# cardlist.append(fomatted_cnum)
# return cardlist
#
# my_card = hide_card(['1234567891234521', '1235451298745123', '2154122245475123'])
# print(my_card)