2019年12月25日

python中try...excpet多种使用方法

摘要: 1 print('\n欢迎使用除法计算器!\n') 2 3 while True: 4 try: 5 x = input('请你输入被除数:') 6 y = input('请你输入除数:') 7 z = float(x)/float(y) 8 print(x,'/',y,'=',z) 9 break 阅读全文

posted @ 2019-12-25 15:04 Through-Target 阅读(2237) 评论(0) 推荐(0) 编辑

python中try...except的用法

摘要: num = [1,2,0,3,1.5,'6'] for x in num: try: # 尝试执行下列代码 print (6/x) except ZeroDivisionError: print('0是不能做除数的!') except TypeError: # 当报错信息为TypeError,执行下 阅读全文

posted @ 2019-12-25 14:16 Through-Target 阅读(8821) 评论(0) 推荐(1) 编辑

python中提取字典中的键值

摘要: 1 # 字典如下 2 movie = { 3 '妖猫传':['黄','染'], 4 '无问西东':['章','王'], 5 '超时空':['雷','佟'] 6 } 7 name = input('请输入演员的名字') # 收集信息 8 for i in movie: # 遍历字典movie的键名 9 阅读全文

posted @ 2019-12-25 13:59 Through-Target 阅读(7084) 评论(0) 推荐(1) 编辑

导航