目錄html
點擊上面連接,安裝python和開發環境python
temp=input("請輸入溫度") if temp[-1:]=='C': F=eval(temp[:-1])*1.8+32 printf(str(F)+'F') elif temp[-1:]=='F': C=(eval(temp[:-1])-32)/1.8 printf(C)
T = input("輸入時間") if T[-3:] == 'min': d = eval(T[:-3]) / 60 / 24 print(str(d) + 'd') elif T[-1:] == 'd': min = eval(T[:-1]) * 60 * 24 print(str(int(min)) + 'min') elif T[-4:] == 'week': d = eval(T[:-4]) *7 print(str(int(d)) + 'd') else : print("輸入錯誤,請從新輸入")
eval主要用於把字符串裏的值進行運算後取出來,如:ide
eval('abcd')=abcdspa
eval('123')=123code
temp = '456123789' print(temp[:]) print(temp[-1]) print(temp[-3:-1]) print(temp[-3:]) print(temp[:-1]) print(temp[-7:-2])
s='nick handsome' print(s[:8:1]) # nick han #從前日後,輸出前八個 print(s[:8:2]) # nc a #從前日後,跳一個輸出 print(s[:8:-1]) # emos # 從右向左,從後往前輸出,第八個字符以後的 print(s[-4::-1]) #從右向左,依次輸出