phython 一期参考答案

n=1
sum=0
while n<=100:
    if n%2= =0:
      sum+=n
     n=n=1
print(sum)
2.
while True:
   n= int(input('请输入一个数字:'))
   if n= =0:
      break
    sum+=n
print(sum)
3.
n=1
while n<=100:
   if n%3==0 and n%5= =0:
      print(n,'是3和5的倍数')
   elif n%5==0:
      print(n,'是5的倍数')
   elif n%3==0:
      print(n,'是3的倍数')
   n=n+1  #避免死循环
4.
for i in range(9):
   print("*",end='')
5.
for i in range(9): #几行
    for i in range(9): #一行几个星星
       print("*",end='')
     print() #换行
6.
for i in range(9):
   for j in range(1,10):
      print("*",end='')
    print()
7.
for i in range(1,10):
   for j in range(1,i+1):
      print(j,'*',i,'=',(j*i),end='\t')
   print()
8.
a=b=c=d=0
while True:
    num=int(input('请输入成绩'))
    if num>=90 and num<=100:
       a+=1
    elif num>=80 and num<90:
       b+=1
    elif num>=60 and num<80:
       c+=1
    elif num>=0 and num<60:
       d+=1
    else:
        print('超出范围请重新输入')
        continue #放回到循环条件判断的位置 必须在循环体中
    str=input('是否继续?y/n')
    if str.__eq__('n'):
        break
print('>=90:',a)
print('>=80:',b)
print('>=60:',c)
print('>=0:',d)
感谢大家的批评与指正,期待您的下次到来(学海无涯与君共勉)

你可能感兴趣的:(phython 一期参考答案)