# python题库面试选集[一]

XAMPP案例 396浏览

python题库选集(一)

``````n = eval(input("请输入正整数:"))
````print("{:->20,}".format(n))````

``````import random
``````brandlist = ['华为','苹果','诺基亚','OPPO','小米']
``````random.seed(0)
``````i=random.randint(0,4)
``````name=brandlist[i]
````print(name)````

``````ntxt = input("请输入4个数字(空格分隔):")
``````nls=ntxt.split()
``````x0 = eval(nls[0])
``````y0 = eval(nls[1])
``````x1 = eval(nls[2])
``````y1 = eval(nls[3])
``````r = pow(pow(x1-x0, 2) + pow(y1-y0, 2), 0.5)
````print("{:.2f}".format(r))````

``````s = input("请输入一个字符串:")
````print("{:=^20}".format(s))````

``````n = eval(input("请输入正整数:"))
````print("{:*>15}".format(n))````

``````n = eval(input("请输入正整数:"))
````print("{:=^14}".format(n))````

``````s = input()
````print("{:=>25,}".format(eval(s)))````

``````s = input()
````print("{:\"^30x}".format(eval(s)))````

``````num = input().split(',')
``````for i in num:
````    print("{:>10}".format(i),end="")````

``````n = input('请输入一个正整数:')
``````for i in range(int(n)):
````    print('{:0>2}{}'.format(i+1,">"*(i+1) ))````

``````a = [3,6,9]
``````b =  eval(input()) #例如：[1,2,3]
``````s=0
``````for i in range(3):
``````    s += a[i]*b[i]
````print(s)````

``````import jieba
``````s = input("请输入一个字符串")
``````n = len(s)
``````m = len(jieba.lcut(s))
````print("中文字符数为{}，中文词语数为{}。".format(n, m))````

``````import jieba
``````txt = input("请输入一段中文文本:")
``````ls=jieba.lcut(txt)
````print("{:.1f}".format(len(txt)/len(ls)))````

``````a, b = 0, 1
``````while a<=100:
``````    print(a, end=',')
````    a, b = b,a+b````

``````a = [3,6,9]
``````b =  eval(input()) #例如：[1,2,3]
``````c = []
``````for i in range(3):
``````    c.append(a[i]+b[i])
````print(c)````

``````a = [3,6,9]
``````b = eval(input()) #例如：[1,2,3]
``````j=1
``````for i in range(len(a)):
``````    b.insert(j,a[i])
``````    j+= 2
````print(b)````

``````s = input()
``````print(s[::-1],end="")
````print(len(s))````

``````n = input()
``````s = "〇一二三四五六七八九"
``````for c in "0123456789":
``````     n=n.replace(c,s[int(c):int(c)+1])
````print(n)````

``````scale = 0.0001  # 成就值增量
``````
``````def calv(base, day):
``````    val = base * pow((1+scale),day*11)
``````    return val
``````
``````print('5年后的成就值是{}'.format(int(calv(1, 5*365))))
``````
``````year = 1
``````while calv(1, year*365) < 100:
``````    year += 1
``````
````print('{}年后成就值是100'.format(year))````

``````ns = input("请输入一串数据：")
``````dnum,dchr = 0,0  #双变量赋值方式
``````for i in ns:
``````    if i.isnumeric(): #如果是数字字符
``````        dnum += 1
``````    elif i.isalpha():
``````        dchr += 1
``````    else:
``````        pass  #空语句，为了保持程序结构的完整性，用于占位
````print('数字个数：{}，字母个数：{}'.format(dnum,dchr))````

``````import random
``````random.seed(123)
``````for i in range(10):
````    print(random.randint(1,1000), end=",")````

``````n = eval(input("请输入数量："))
``````if n>0 and n<=1:
``````    cost=n*160
``````elif n<=4:
``````    cost=n*160*0.9
``````elif n<=9:
``````    cost=n*160*0.8
``````else:
``````    cost=n*160*0.7
``````cost=int(cost)
````print("总额为:",cost)````

``````n = eval(input("请输入一个数字:"))
````print("{:+^11}".format(chr(n-1)+chr(n)+chr(n+1)))````

``````import jieba
``````txt = input("请输入一段中文文本:")
``````ls=jieba.lcut(txt)
``````for i in ls[::-1]:
````    print(i,end='')````

``````import random
``````random.seed(0)
``````s = 0
``````for i in range(5):
``````    n = random.randint(1,97)  # 产生随机数
``````    s = s+n**2
````print(s)````

``````import random
``````random.seed(100)  # 此处可多行
``````s = 0  #
``````for i in range(3):
``````    n=random.randint(1,9)
``````    s=s+n**3# 此处可多行
````print(s)````

``````a, b, c = eval(input())
``````ls = []
``````for i in range(c):
``````    ls.append(a+b*i)
````print(ls)````

``````a, b, c = eval(input())
``````ls = []
``````for i in range(c):
``````    ls.append(str(a*(b**i)))
````print(",".join(ls))````

``````while True:
``````    try:
``````        a = eval(input('请输入一个正整数: '))
``````        if a > 0 and int(a)==a:
``````            print(a)
``````            break
``````        else:
``````            print("请输入正整数")
``````    except:
````        print("请输入正整数")````

``````std = [['张三',90,87,95],['李四',83,80,87],['王五',73,57,55]]
``````modl = "亲爱的{}, 你的考试成绩是: 英语{}, 数学{}, Python语言{}, 总成绩{}.特此通知。"
``````
``````for st in std:
``````    cnt = 0   #总成绩初始值
``````    for i in range(3): #循环三科成绩
``````        cnt += st[i+1] #成绩求和
````    print(modl.format(st[0],st[1],st[2],st[3],cnt))````