赞
踩
for i in range(10):
for j in range(1,i+1):
print("{}*{}={}".format(i,j,i*j),end= " ")
print()
for num in range(100,1000):
ge_num=num%10
bai_num=num//100
shi_num=(num-bai_num*100-ge_num)//10
if ge_num**3+shi_num**3+bai_num**3==num:
print("100-1000的水仙花数有:")
print(num)
sum = int(input('请输入一个三位数:'))
sum1 = sum%10
sum2 = sum//100
sum3 = (sum-sum2*100-sum1)//10
if sum1**3+sum2**3==sum:
print('%d是水仙花数'%sum)
else:
print('%d不是水仙花数'%sum)
n=int(input('Please input a number:' )) if(n==0): print('no reason') elif(n%2==0): i=2 sum=0 while(i<=n): sum=sum+(1/i) i=i+2 else: i=1 sum=0 while(i<=n): sum=sum+(1/i) i=i+2 print("sum=",sum)
for i in range(10):
for j in range(1,i+1):
print("{}*{}={}".format(i,j,i*j),end= " ")
print()
5.从100-1000找出所有的水仙花数
#从100-1000找出所有的水仙花数 a=100 while a<999: a=a+1 if(a==(a//100)**3+((a//10)%10)**3+(a%10)**3): print('100-1000中水仙花数为:',a) #定义一个函数 def flowersum(): for i in range(100,1000): a=i//100 b=i//10%10 c=i%10 if i==a**3+b**3+c**3: print(i) flowersum()
import random computer = random.randint(0,100) plays = eval(input(" 请输入你猜想的结果:")) go="y" while go=="y": if plays > computer: print("太大了!") plays = eval(input(" 请输入你猜想的结果:")) elif plays < computer: print("太小了!") plays = eval(input(" 请输入你猜想的结果:")) else: print("猜中了!") go = input("是否继续:是(y),否(n)") if go == "y" : computer = random.randint(0, 100) plays = eval(input(" 请输入你猜想的结果:")) else: break print("GOOD BYE!")
n=1
for i in range(9):
n=2*n+2
print(n)
x=1
for i in range(10,0,-1):
print('第%d天的桃子数为%d个'%(i,x))
x=2*(x+1)
8.列表存放
a=[1,20,32,14,5,62,78.38,9,10]
for i in range(9):
if a[i] > a[i+1]:
a[i],a[i+1]=a[i+1],a[i]
print(a)
9.观众投票测试
list = [] for i in range(10): list.append(eval(input("输入评分:"))) list.sort() print(list) list.pop(0) print(list) list.pop(8) print(list) list.append(9) print(list) average=sum(list)/len(list) print(average)
tuple=(7,1,2,23,4,5)
print(len(tuple))
print(max(tuple))
print(min(tuple))
list1=[1,2,3,4]
list2=list1+list(tuple)
print(list2)
count = {}
for i in "python is sample":
if i in count:
count[i]+=1
else:
count[i]=1
print (count)
num=[]
for i in range(30):
num.append(eval(input('请输入学生成绩')))
sum=0
for g in num:
sum+=g
avg=sum/30
print(avg)
#方法一 def Sushu(n): for i in range(2,n): if n%i ==0: print('no') break else: print(n) def main(): for i in range(101): Sushu(i) main() #方法二:函数 def sushu(num): for i in range (2, num): if(num%i)==0: print("NO!") break else: print("YES!") num=eval(input("请输入一个数:")) (sushu(num))
n=eval(input("请输入一个数:"))
def fact(n):
if n==0:
return 1
else:
return n*fact(n-1)
print(fact(n))
from tkinter import*
window=Tk()
window.title(" pig pig pig")
window.geometry('500x400')
t=Text()
t.pack()
def print_hello():
t.insert('1.0',' pig pig pig\n')
Button(window,text='press',width=20,height=2,command=print_hello).pack()
window.mainloop()
str1="python is simple"
d={}
for c in str1:
if c in d.keys():
d[c]+=1
else:
d[c]=1
print(d)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。