码迷,mamicode.com
首页 > 编程语言 > 详细

python小练习

时间:2019-10-11 20:27:52      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:code   com   end   append   一个   mic   else   pytho   form   

技术图片

 

‘‘‘
#第一题
def sum1(str):

sum=0
for x in str:
sum=sum+x
return sum
if __name__ == ‘__main__‘:
x=input("请输入一个整型字符串:")
lst=[int(i) for i in x]
print(sum1(lst))‘‘‘
‘‘‘
#第二题
str=input("请输入一个字符串:")
print(str[::-1])‘‘‘
‘‘‘
#第三题
def max1(a):
m=a[0]
for x in a:
if x>m:
m=x
return m
if __name__ == ‘__main__‘:
x=input("请输入一个整数列表,用空格隔开:").split()
lst=[int(i) for i in x]
print(max1(lst))‘‘‘
‘‘‘
#第四题
lst4=input().split(",")
newlst2=[]
for i in lst4:
newlst2.append(i)
print(newlst2)‘‘‘
‘‘‘
#第五题
lst3=input().split(",")
newlst3=[]
for x in lst3:
if x==‘0‘:
continue
if x==‘None‘:
continue
if x==‘False‘:
continue
else:
newlst3.append(x)
print(newlst3)‘‘‘
‘‘‘
#第六题
x=input().split(",")
lst=[int(i) for i in x]
count=0
sum=0
for i in lst:
count=count+1
sum=sum+i
svr=sum/count
print("平均数为{:.3f}".format(svr))‘‘‘
‘‘‘#第七题
x=input().split(",")
lst=[int(i) for i in x]
lst.sort(reverse=True)
print(lst)‘‘‘
‘‘‘#第八题
x=input().split(",")
lst=[str(i) for i in x]
for i in range(len(lst)):
lst[i]=len(lst[i])
print(lst)‘‘‘
‘‘‘#第九题
x=input().split(",")
lst=[int(i) for i in x]
m=lst[0]
for i in lst:
if abs(i)>abs(m):
m=i
print(m)‘‘‘
‘‘‘#第十题
s=input("输入任意数据:")
t=[int(n) for n in s.split(‘,‘)]
a=1
for i in range(len(t)):
a*=t[i-1]
print("乘积为{}".format(a))‘‘‘
‘‘‘#第十一题
s=input("输入一组数据:")
t=[int(n) for n in s.split(‘,‘)]
a=input("输入与上组数据等长的数据:")
b=[int(n) for n in s.split(‘,‘)]
for i in range(len(t)):
t[i]=t[i]*b[i]
print("两个向量的内积为:",t)‘‘‘

 

 

 

 

 

‘‘‘
#第一题
def sum1(str):

sum=0
for x in str:
sum=sum+x
return sum
if __name__ == ‘__main__‘:
x=input("请输入一个整型字符串:")
lst=[int(i) for i in x]
print(sum1(lst))‘‘‘
‘‘‘
#第二题
str=input("请输入一个字符串:")
print(str[::-1])‘‘‘
‘‘‘
#第三题
def max1(a):
m=a[0]
for x in a:
if x>m:
m=x
return m
if __name__ == ‘__main__‘:
x=input("请输入一个整数列表,用空格隔开:").split()
lst=[int(i) for i in x]
print(max1(lst))‘‘‘
‘‘‘
#第四题
lst4=input().split(",")
newlst2=[]
for i in lst4:
newlst2.append(i)
print(newlst2)‘‘‘
‘‘‘
#第五题
lst3=input().split(",")
newlst3=[]
for x in lst3:
if x==‘0‘:
continue
if x==‘None‘:
continue
if x==‘False‘:
continue
else:
newlst3.append(x)
print(newlst3)‘‘‘
‘‘‘
#第六题
x=input().split(",")
lst=[int(i) for i in x]
count=0
sum=0
for i in lst:
count=count+1
sum=sum+i
svr=sum/count
print("平均数为{:.3f}".format(svr))‘‘‘
‘‘‘#第七题
x=input().split(",")
lst=[int(i) for i in x]
lst.sort(reverse=True)
print(lst)‘‘‘
‘‘‘#第八题
x=input().split(",")
lst=[str(i) for i in x]
for i in range(len(lst)):
lst[i]=len(lst[i])
print(lst)‘‘‘
‘‘‘#第九题
x=input().split(",")
lst=[int(i) for i in x]
m=lst[0]
for i in lst:
if abs(i)>abs(m):
m=i
print(m)‘‘‘
‘‘‘#第十题
s=input("输入任意数据:")
t=[int(n) for n in s.split(‘,‘)]
a=1
for i in range(len(t)):
a*=t[i-1]
print("乘积为{}".format(a))‘‘‘
‘‘‘#第十一题
s=input("输入一组数据:")
t=[int(n) for n in s.split(‘,‘)]
a=input("输入与上组数据等长的数据:")
b=[int(n) for n in s.split(‘,‘)]
for i in range(len(t)):
t[i]=t[i]*b[i]
print("两个向量的内积为:",t)‘‘‘

 

 

 

 

 

 

 

 

 

 

 

 

 

 




 

 

 

 

 

 

 

 

 

 




python小练习

标签:code   com   end   append   一个   mic   else   pytho   form   

原文地址:https://www.cnblogs.com/c1q2s3/p/11656147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!