5月13日木叶下循环

#求1500-3000之间,能被7和5整除的数
for i in range(1500,3001):
    if (i%5)==0 and (i%7)==0:
        print (i)   


# In[89]:


#用for循环,打印如下图形:
for i in range(1,5):
    for j in range(i):
        print("*",end="")
    print()

for i in range(5,0,-1):   
    for j in range(i):
        print("*",end="")
    print() 


# In[117]:


#写一个脚本,打印list中的每一项,以及这项的type
datalist = [1452,11.23,1+2j,True,'w3resource',(0,-1),[5,12],{"calss":'V',"section":'A'}]
for i in range(len(datalist)):
    print (datalist[i],type(datalist[i]))


# In[91]:


#打印0-6之间,除3和6的数
for i in range(0,7):
    if i!=3 and i!=6:
        print (i) 


# In[115]:


#写一个脚本,输入字符串,求出字符串中数字和字符的数目
s = input("请输入一个字符串")
letters = 0
digit = 0
for i in s:
    if i.isalpha():  
        letters += 1
    elif i.isdigit(): 
        digit += 1
print("[%s]中字母的个数=%d,数字的个数=%d" % (s,letters,digit)) 


# In[113]:


#打印如下图形(字母E, X, Z)
x = ' '
y = "*"
print (5*y,10*x,y,3*x,y,10*x,7*y)
print (y,14*x,y,3*x,y,15*x,y,x)
print (y,15*x,y,x,y,15*x,y,2*x)
print (4*y,14*x,y,16*x,y,2*x)
print (y,15*x,y,x,y,13*x,y,4*x)
print (y,14*x,y,3*x,y,11*x,y,5*x)
print (5*y,10*x,y,3*x,y,10*x,7*y)


# In[95]:


#输入三角形的三条边长,求面积
import math
a = float(input("三角形第一条边边长"))
b = float(input("三角形第二条边边长"))
c = float(input("三角形第三条边边长"))
if (a+b>c and a+c>b and b+c>a):
    p = (a+b+c)/2
    S = math.sqrt(p*(p-a)*(p-b)*(p-c))
    print ("三角形的面积是",S)
else:
    print ("请输入正确的三角形边长!")


# In[96]:


#输入三角形的三条边长,判断是否是特殊三角形(等边、等腰、直角)
import math
a = float(input("三角形第一条边边长"))
b = float(input("三角形第二条边边长"))
c = float(input("三角形第三条边边长"))
if (a+b>c and a+c>b and b+c>a):
    if (a==b or b==c or a==c):
        if (a==b==c):
            print ("输入的是等边三角形")
        else:
            print ("输入的是等腰三角形")
    elif (a*a+b*b == c*c or a*a+c*c == b*b or b*b+c*c == a*a):
        print ("输入的是直角三角形")
    else:
        print ("输入的是一般三角形")
else:
    print ("请输入正确的三角形边长!")


# In[99]:


#求出range(1, 10000)的极差、中位数,平均数,方差
list1 = range(1, 10000)
if len(list1)%2==0:
    median = (list1[len(list1)] + list1[len(list1)-1])/2
else:
    median = list1[len(list1)//2]
average = sum(list1)/len(list1)
print ("极差为:",max(list1)-min(list1))
print ("中位数为:",median)
print ("平均数为:",average)
print ("方差为:",sum([(x - average) ** 2 for x in list1]) / len(list1))


# In[98]:


#用for循环,打印如下数字
for i in range(1,10):
    for j in range(i):
        print((str(i)),end="")
    print ()


# In[87]:


#输入字符串,求元音、辅音字母的个数
s = input("请输入一个字符串")
vowel = 0
consonant = 0
for i in s:
    if i.isalpha():
        if( i=='A' or i=='a' or i=='E' or i=='e' or i=='I' or i=='i' or i=='O' or i=='o'or i=='U' or i=='u'):
            vowel +=1
        else:
            consonant +=1
print("[%s]中元音字母的个数=%d,辅音字母的个数=%d" % (s,vowel,consonant))        


# In[111]:


#求出100到400之间,个、十、百位都是偶数的数,打印成一行,并用逗号分开
for i in range(100,401):
    if ((i//100)%2==0 and ((i%100)//10)%2==0 and (i%10)%2==0):
        print (i,end=",")


# In[112]:


#输入字符串,判断字符串是否可以转化成整数
s = input("请输入一个字符串")
if s.isdigit():
    print("字符串可以转化成整数")
else:
    print("字符串不可以转化成整数")

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值