Python基礎文法學習完成,先刷基礎題100道鞏固 ,附 題目、代碼、知識分析
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1000.html
代碼:
s = input().split();
print((int)(s[0])+(int)(s[1]))
知識分析:
1、python輸入 input()
2、split() 是分割字元串操作
3、python可以用str[0] 取字元串下标為0的字元
1000、A+B Problem
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1010.html
代碼:
while True:
s=input().split()
print((int)(s[0])+(int)(s[1]))
分析知識:
1、Python的布爾類型有 True False 記住是大寫
2、while True : 後面冒号必須有 括号不一定需要有,規範是沒有 和java不同
1010、A+B for Input-Output Practice (I)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1011.html
代碼:
num = (int)(input())
for i in range(1,num+1):
s = input().split()
print((int)(s[0])+(int)(s[1]))
知識分析:
1、for 循環使用 結構 for i in range(1,num+1)
則 i 的取值範圍是 1 到 num
1011、A+B for Input-Output Practice (II)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1012.html
代碼:
while True:
s = input().split()
if (int)(s[0])==0 and (int)(s[1])==0:
break
print((int)(s[0])+(int)(s[1]))
知識分析:
1、python的且運算是and 或運算是or
1012、A+B for Input-Output Practice (III)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1013.html
代碼:
while True:
s=input().split()
if s==['0']:
break
sum = 0;
for i in range(1,len(s)):
sum=sum+(int)(s[i])
print(sum)
1013、A+B for Input-Output Practice (IV)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1014.html
代碼:
s = input()
for i in range(0 , int(s)):
s=input().split()
sum = 0;
for i in range(1,len(s)):
sum=sum+(int)(s[i])
print(sum)
1014、A+B for Input-Output Practice (V)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1015.html
代碼:
while True:
s=input().split()
sum=0
for i in range(1,len(s)):
sum+=(int)(s[i])
print(sum)
知識分析:
無
1015、A+B for Input-Output Practice (VI)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1016.html
代碼:
while True:
s=input().split()
print((int)(s[0])+(int)(s[1]))
print()
1016、A+B for Input-Output Practice (VII)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1017.html
代碼:
s=input()
for i in range(0,(int)(s)):
ss = input().split()
sum = 0;
for j in range(1,len(ss)):
sum+=(int)(ss[j])
print(sum)
print()
1017、A+B for Input-Output Practice
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1123.html
代碼:
num=(int)(input())
if num==0:
print(1)
else:
sum = 1;
i=0
for i in range(1,num+1):
sum *= i
print(sum)
知識分析:
1、if else 裡面都需要有:
1123、求階乘(循環結構)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1201.html
代碼:
s=input().split(" ")
#将三個字元串加入清單
list = []
list.append(s[0])
list.append(s[1])
list.append(s[2])
list.sort()
for i in range(len(list)):
print(list[i],end='')
print(" ",end='')
知識分析:
1、list添加元素方法 append
2、list排序方法 sort()
3、輸出不換行 加 ,end=''
1201、字元串排序
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1249.html
代碼:
while True:
s = input()
print(s.title())
知識分析:
1、input()輸入後即 字元串
2、s.title() 内置方法 将每個單詞的第一個字母轉為大寫 其餘小寫
其他方法如下:
str = "www.runoob.com"
print(str.upper()) # 把所有字元中的小寫字母轉換成大寫字母
print(str.lower()) # 把所有字元中的大寫字母轉換成小寫字母
print(str.capitalize()) # 把第一個字母轉化為大寫字母,其餘小寫
print(str.title()) # 把每個單詞的第一個字母轉化為大寫,其餘小寫
執行以上代碼輸出結果為:
WWW.RUNOOB.COM
www.runoob.com
Www.runoob.com
Www.Runoob.Com
1249、首字母變大寫
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1442.html
代碼:
num=(int)(input())
for i in range(0,num):
s = input().split(" ")
# 用空格分割 是字元串 轉成整形 存到清單中
list = []
list.append((int)(s[0]))
list.append((int)(s[1]))
list.append((int)(s[2]))
ave = (list[0]+list[1]+list[2])/3 #算平均數
isLarge = 0 # 3個數中 大于平均數的個數
for j in list:
if j > ave:
isLarge+=1
if isLarge>1:
print("Yes")
else:
print("No")
知識分析:
1、range(0,num) 的取值範圍是0到num-1
2、 s = input().split(" ") 擷取的是用空格分割的字元串 并存入到清單中
比如輸入 : 1 2 3
s 的值就是 : ['1', '3', '4']
1442、優越數
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZuUWYxYmZhR2MiNjY3QGMjFGZlNTOzUWZjJGO2YzM1MWMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.gif)
題目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2247.html
代碼:
s=input().split(" ")
print(s[0].count(s[1]))
知識分析:
1、str.count(s) 傳回s在str中出現的次數
2247、統計次數問題