Python入门学习札记
学习课程:风变编程 - Python入门
https://www.pypypy.cn/
1、输入数组,判断结果
print('输入学生的成绩,每个成绩以,键隔开\n')
arr = input("")
print('\n')
HistoryScore = [int(n) for n in arr.split(',')]
#将输入每个数以,键隔开做成数组
HistoryScore_length = len(HistoryScore)
print('总计有',HistoryScore_length,'个学生\n')
print('学生的成绩是:',HistoryScore,'\n')
count = 0
while (count < HistoryScore_length):
if HistoryScore[count] >= 60:
print('第',str(count+1),'个同学',HistoryScore[count],'分: 你已经及格')
if HistoryScore[count] >= 80:
print('评语:你很优秀')
else:
print('评语:你只是一般般')
else:
print('第',str(count+1),'个同学',HistoryScore[count],'分: 你不及格')
if HistoryScore[count] < 30:
print('评语:学渣')
else:
print('评语:还能抢救一下')
print('程序结束\n')
count = count + 1
输入:90,70,50,20
2、多层if-elif-else语句嵌套
Salary = int(input("请输入工资数:"))
print('\n')
if Salary <= 500:
print('“欢迎进入史塔克穷人帮前三名”')
if 100 < Salary <=500:
print('“请找弗瑞队长加薪”','\n','程序结束')
else:
print('“恭喜您荣获“美元队长”称号!”','\n','程序结束')
elif 500< Salary <=1000:
print('“祝贺您至少可以温饱了。”','\n','程序结束')
else Salary > 1000:
print('“经济危机都难不倒您!”')
if 1000 < Salary <=20000:
print('“您快比钢铁侠有钱了!”','\n','程序结束')
else:
print('“您是不是来自于瓦坎达国?”','\n','程序结束')
输入:20000
###3、输入输出,浮点运算的小数位
print('您好,欢迎来到古灵阁,请问您需要帮助吗?\n请输入数字:')
str = input('1 需要;2 不需要\n')
num = int(str)
if num == 1:
print('请问您需要什么帮助呢?\n请输入数字:')
str = input('1 存取款;2 货币兑换;3 咨询 \n')
else:
print('好的,再见。')
task = int(str)
if task == 1:
print('请去存取款窗口\n程序结束')
elif task == 3:
print('请去咨询窗口\n程序结束')
elif task == 2:
print('金加隆和人民币的兑换率为1:51.3,即一金加隆=51.3人民币')
str = input('请问您需要兑换多少金加隆呢?\n')
money = float(str)
cal = format(money*51.3, '.2f')
#将产生一个浮点数作为一个四舍五入为两个小数点的字符串
print('那么,您需要付给我',cal,'人民币。\n程序结束')
else:
print('不在服务范围,程序结束')