# e=input("输入自然数字字符串:")
# result=0
# for x in e:
# result+=eval(x)-------------------第一题
# print(result)
# def rev(str):
# print(str[-1::-1])
# if __name__ == ‘__main__‘:-----------------第二题
# st=input()
# rev(st)
# def max(*a):
# m=a[0]
# for x in a:
# if x>m:
# m=x
# return m
# if __name__ == ‘__main__‘:------------------------第三题
# e=eval(input())
# result=max(*e)
# print("最大值是:{}".format(result))
# a=[200,300,456,456]
# b=[]
# for i in range(len(a)):----------数字列表转换成字符串列表------第四题
# b.append(str(a[i]))
# print(b)
# a=[234,354,‘a‘,None,False]
# b=[]
# for i in range(len(a)):
# if(bool(a[i])==True):---------------bool字符判断--------第五题
# b.append(a[i])
# print(b)
当然这里的数组都可以换成input控制台输入类型,eval(input())默认为‘,’(逗号)隔开
# def avg(*a):
# result=0
# n=0
# for x in a:
# result+=x
# n+=1
# avge=result/n
# return avge
# if __name__ == ‘__main__‘:
# e=eval(input(":"))
# print("平均数为:{:.3f}".format(avg(*e)))------------------计算平均数-------第六题
# def sort(a):
# str2=[]
# max=a[0]
# for i in range(len(a)):
# for j in range(0,len(a)-i-1):
# if a[j]<=a[j+1]:
# a[j],a[j+1]=a[j+1],a[j]
# for x in range(len(a)):
# str2.append(a[x])
# print(str2)
# if __name__ == ‘__main__‘:
# e=[23,34,435,78,21,32,23]----------------------降序排列----------第七题
# sort(e)
# def index_sort(arr):
# b=[]
# for x in range(len(arr)):
# index=len(str(arr[x]))
# b.append(index)
# print(b)
# if __name__ == ‘__main__‘:-----------------------输出位数-------------第八题
# e=eval(input(":"))
# index_sort(e)
# def num1(num):
# if num>=0:
# num=num
# else:
# num*=-1
# return num
# def max_num1(arr):
# max=arr[0]
# for x in range(len(arr)):
# if num1(arr[x])>=max:
# max=arr[x]
# print(max)
# if __name__ == ‘__main__‘:
# e=eval(input("用于比较绝对值大小:"))-------------比较绝对值大小------第九题
# max_num1(e)
# def hort(arr):
# result=1
# for x in range(len(arr)):
# result*=arr[x]
# print(result)
# if __name__ == ‘__main__‘:--------------------列表数字相呈乘------第十题
# e=eval(input())
# hort(e)
# a=[1,2,3,4]
# b=[5,6,7,8]
# result=0
# for x in range(len(a)):
# result+=(a[x]*b[x])--------------------向量内积-------------第十一题
# print(result)
也许看上去很简单,但是我i觉得重要的是这些基本数组操作的思想,方法千千万,思路有了,自然就得到了锻炼,希望对各位看的小伙伴有帮助!
原文:https://www.cnblogs.com/cybg/p/11708122.html