def f(n):
if n%2!=0:
return True
else:
return False
sum=0
mul=1
for i in range(1,100):
if f(i):
sum+=i
mul*=i
print(sum,mul)
def f(x):#判断水仙花
a=str(x)
sum=eval(a[0])**3+eval(a[1])**3+eval(a[2])**3
if x==sum:
return True
else:
return False
for i in range(100,1000):
if f(i):
print(i)
for i in range(21):
for j in range(34):
for k in range(301):
if 5*i+3*j+k/3==100 and i+j+k==100:
print(i,j,k)
def sushu(n):
if n>1:
for i in range(2,n):
if n%i!=0:
return True
else:
return False
def huiwen(number):
length = len(str(number))#转换为字符串的长度
list = [int(x) for x in str(number)]
for j in range(length // 2):
if list[j] != list[length - 1 - j]:
return False
return True
for j in range(2,1000):
if sushu(j) and huiwen(j):
print(j)
仿照以上表格结构,创建一个DataFrame对象,字典对象,Jason对象,并将其分别保存至文件。
import pandas as pd
import numpy as np
arr=np.array([[1,5,8,8],[2,2,4,9],[7,4,2,3],[3,0,5,2]])
n_arr=pd.DataFrame(arr,columns=['A','B','C','D'])
print(n_arr)
def f(x):#判断一个数是否是完数
sum=0
for i in range(1,x):
if x%i==0:
sum+=i
if sum==x:
return True
for j in range(1,1000):
if f(j):
print(j)
a=list(input())
a.sort()
for i in a:
if i!=' ':
print(i,end=' ')
import random as r
n=int(input('随机数个数:'))
b=[]
for i in range(n):
a=r.randint(1,101)
print(a,end=' ')
if a%2==0 and a%4!=0:
b.append(a)
print('\n')
sum1=0
for j in b:
sum1+=j
print(sum1)
def f(n):#求1+……+n的和
sum=0
for i in range(1,n+1):
sum+=i
return sum
n=eval(input())
allsum=0
for j in range(1,n+1):
allsum+=f(j)
print(allsum)