def get_score():
""""""
while true:
try:
int_score = int(input("請輸入成績:"))
except exception as s:
print("有異常,重新輸入", s)
continue
if 0 <= int_score <= 100:
print(int_score)
break
get_score()
def get_try_except(num):
"""異常處理
:param num:
:return:
"""while true:
try:
return num
except:
print("輸入錯誤,重新輸入")
get_try_except(int(input("aaaaa:")))
class scoreerror(exception):
def __init__(self,score):
self.score=score
def get_score():
""""""
int_score = int(input("請輸入成績:"))
if 0 <= int_score <= 100:
print(int_score)
else:
raise scoreerror(int_score)
try:
get_score()
except scoreerror as e:
print("錯誤資訊:",e.score)
# 練習1:
tuple_01=("悟空","八戒","唐長老","沙師弟","女施主")
itertup=tuple_01.__iter__()
while true:
try:
print(itertup.__next__())
except:
print("越界嘍,師傅請放開你的雙手,讓徒弟來")
break
# 練習2:
# 不使用for迴圈,獲取字典中的所有元素
dict_01=
iterdict=dict_01.__iter__()
while true:
try:
k=iterdict.__next__()
v=dict_01[k]
print(k,v)
except:
print("越界嘍,師傅請放開你的雙手,讓徒弟來")
break
python15個程式設計技巧
1同時給多個變數賦值 a b c 1,ab 1,2 2給兩個變數的交換 a,b b,a3序列解包 student jeryy 30 m name student 0 age student 1 gender student 2 name,age,gender student就是解包的操作,特定對序列...
自學python 15 迭代器
可迭代的物件 1.生成器2.元組,列表,集合,字典,字串。判斷乙個物件是否是可迭代的 from collections import iterable list1 1 4,7 8,9 f isinstance abc iterable print f true f isinstance 111 it...
Python 15種主流框架
從github中整理出的15個最受歡迎的python開源框架。這些框架包括事件i o,baiolap,web開發,高效能網路通訊,測試,爬蟲等。django 應該是最出名的python框架,gae甚至erlang都有框架受它影響。django是走大而全的方向,它最出名的是其全自動化的管理後台 只需要...