第零級
------------------------------------------------------
------------------複雜的數值運算
------------------複雜的數值運算
x=int(input("x="))
y=int(input("y="))
z=int(input("z="))
print("-(x*x*x)+y*(x*x)-z*(x)+4=",-(x*x*x)+y*(x*x)-z*(x)+4)
=========
-(x*x*x)+y*(x*x)-z*(x)+4= 2
------------------------------------------------------
------------------復刻版數值運算
x=int(input("x="))
if x>0:
f=(x*x*x)-311*(x*x)-72*(x)-4
else:
f=2*(x*x*x)+78*(x*x)-2
print("abs(f)/10007=",abs(f)/10007)
print("abs(f)%10007=",abs(f)%10007)
=========
x=3
abs(f)/10007= 0.2989907065054462
abs(f)%10007= 2992
=========
x=-3
abs(f)/10007= 0.0645548116318577
abs(f)%10007= 646
------------------餘數版數值運算
x=int(input("x="))
y=int(input("y="))
f=2*(x*x*x*x*x)+4*(x*x*x)+7
print("f % y=",f % y)
=========
------------------------------------------------------
------------------字串開頭之判斷
------------------
x=2
y=3
f % y= 1
------------------字串開頭之判斷
Str=input("輸入任意資料:")
if ord(Str[0])>=65:
print("第一個輸入 是文字!")
else:
print("第一個輸入 是數字!")
=========
輸入任意資料:abc
第一個輸入 是文字!
=========
輸入任意資料:3abc
第一個輸入 是數字!
第一級
------------------------------------------------------1010------------------
Str=input("輸入任意數字,以<space>隔開,<Enter>結束:")
intLst=[int(i) for i in Str.split() ]
Max=0
for i in intLst:
if i>Max:
Max=i
print("Max=",Max)
=========
輸入任意數字,以<space>隔開,<Enter>結束:7 8 9 6 3 2 1
Max= 9
------------------------------------------------------
------------------
------------------
Str=input("輸入任意數字,以<space>隔開,<Enter>結束:")
intLst=[int(i) for i in Str.split() ]
print("反向輸出:",intLst[::-1])
=========
輸入任意數字,以<space>隔開,<Enter>結束:7 8 9 6 3
反向輸出: [3, 6, 9, 8, 7]
------------------------------------------------------
------------------統計每個字串所用到的字元數量
------------------統計每個字串所用到的字元數量
n=int(input("輸入次數:"))
for i in range(n):
#9個元素,預設都為0
LstCnt=[0 for i in range(0,9+1)]
Str=input("輸入任,數字串:")
#將輸入數字串,轉成一個個數字list
intLst=[int(i) for i in list(Str)]
for j in intLst:
#統計每個出現在intLst中個別數字,出現次數
LstCnt[int(j)]+=1
print(LstCnt)
=========
輸入次數:5
輸入任,數字串:0
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
輸入任,數字串:00
[2, 0, 0, 0, 0, 0, 0, 0, 0, 0]
輸入任,數字串:5140514
[1, 2, 0, 0, 2, 2, 0, 0, 0, 0]
輸入任,數字串:99999999999999999999999999999999999999999999999999
[0, 0, 0, 0, 0, 0, 0, 0, 0, 50]
輸入任,數字串:1234567890
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
------------------------------------------------------
------------------
------------------
#HelloWorld!
Str=input("輸入字串: ")
print("反向輸出:",Str[::-1])
#0,1,2,3,4,5,6,7,8,9,10 =>索引值從左
print("反向輸出: ",end="")
for i in range(len(Str)-1,-1,-1):
print(Str[i],end="")
#-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1 =>索引值從右
print("\n反向輸出: ",end="")
for i in range(-1,-len(Str)-1,-1):
print(Str[i],end="")
=========
輸入字串: HelloWorld!
反向輸出: !dlroWolleH
反向輸出: !dlroWolleH
反向輸出: !dlroWolleH
------------------------------------------------------
------------------
------------------
Str=input("輸入字串: ")
lower=0;upper=0
for i in Str:
if ord(i)>=97 and ord(i)<=122:
lower+=1
elif ord(i)>=65 and ord(i)<=90:
upper+=1
print("共計輸入:",len(Str)," 大寫字母:",upper," 小寫字母:",lower)
=========
輸入字串: HelloPython
共計輸入: 11 大寫字母: 2 小寫字母: 9
------------------------------------------------------
------------------
------------------
Str=input("輸入字串: ")
print("大小寫轉換:",end="")
for i in Str:
if ord(i)>=97 and ord(i)<=122:
print(chr(ord(i)-32),end="")
elif ord(i)>=65 and ord(i)<=90:
print(chr(ord(i)+32),end="")
=========
輸入字串: aaBBCCCdddEf
大小寫轉換:AAbbcccDDDeF
------------------------------------------------------
------------------
------------------
Str=input("輸入數字串:")
#0~9 十個數字,預設出現次數皆為0
cntLst=[0 for i in range(10)]
#1 9 3 5 1 4 0 9 8 1 4 2 4
#1935140981424
for i in Str:
if i!=" ":
#統計出現數字
cntLst[int(i)]+=1
#找出list中數值最大
Max=max(cntLst)
print("出現數字最多:",end="")
#數值最大,可能不只1個
for i in range(len(cntLst)):
if cntLst[i]==Max:
print(i,end=" ,")
print("\n出現次數:",Max)
=========
輸入數字串:1935140981424
出現數字最多:1 ,4 ,
出現次數: 3
------------------------------------------------------1017
------------------
------------------
nStr=input("輸入數字串1,<space>隔開:")
nInt=[int(i) for i in nStr.split( )]
mStr=input("輸入數字串2,<space>隔開:")
mInt=[int(i) for i in mStr.split( )]
for i in mInt:
for j in nInt:
print("{0:4d}".format(i*j),end="")
print()
=========
輸入數字串1,<space>隔開:1 2 3 4
輸入數字串2,<space>隔開:1 10 100
1 2 3 4
10 20 30 40
100 200 300 400
------------------------------------------------------1018
------------------
------------------
n=int(input("輸入多少個文字串:"))
Lst=[]
for i in range(0,n):
Str=input("輸入文字串,<Enter>完成:")
Lst.append(Str)
print("反向輸出這些字串:")
for j in Lst[::-1]:
print(j)
=========
輸入多少個文字串:5
輸入文字串,<Enter>完成:AAAAA
輸入文字串,<Enter>完成:bbb
輸入文字串,<Enter>完成:CCcc
輸入文字串,<Enter>完成:ddd
輸入文字串,<Enter>完成:EE
反向輸出這些字串:
EE
ddd
CCcc
bbb
AAAAA
------------------------------------------------------
------------------
------------------
import sys
#僅接受一行的全部輸入
#在末尾加上.strip()或.strip(“\n”)去掉末尾的換行符
print("Enter string:",end="")
line=sys.stdin.readline().strip()
#沒輸入,<Enter>結束
while line != "":
print(line)
print("Enter string:",end="")
line=sys.stdin.readline().strip()
=========
Enter string:Hello
Hello
Enter string:Python
Python
Enter string:
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
------------------------------------------------------
------------------
------------------
=========
沒有留言:
張貼留言