zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python的基础试题

2023-09-14 09:12:45 时间

        试题1:请使用 Python 中的循环打印输出从1到100的所有奇数。

        试题2:请将字符串“你好SsS我正在学 Python@#@#现在需要&*&*&修改字串”中的符号变成一个空格,需要输出的格式为:“你好 我正在学 Python 现在需要 修改字符串”。
        

        试题3:输出9×9乘法口诀表。

        试题4:请写出一个函数,当输入函数变量月利润为 I 时,能返回应发放奖金
的总数。例如,输出“利润为100000元时,应发放奖金总数为10000元”。

        其中,企业发放的奖金根据利润提成。利润( I )低于或等于10力元时,奖金可提10%:利润高于10万元,低于20万元时,低10力元的部分按10%提成,高于10万元的部分,可提成7.5%:利润在20万元到40力元之间时,高于20万元的部分可提成5%;利润在40万元到60万元之间时,高于40万元的部分可提成3%;利润在60力元到100力元之间时,高于60万元的部分可提成
1.5%:利润高于100万元时,超过100力元的部分按1%提成。

        试题5:用字典的值对字興进行排序,将{1:2,3:4,4:3,2:1,0:0}按照字典的值
从大到小进行排序。

试题1:

for i in range(100):
    if i%2 not in [0]:
        print(i)  #方法很多

试题2:

s = input()
str = s.replace('SsS',' ').replace('&*&*&',' ').replace('@#@#',' ')
print(str)
import re
s = input()
str1 = re.sub('[@#Ss&&*%]+',' ',s)
print(str1)

试题3:

for i in range(1,10):
    for j in range(1,10):
        if i>=j:
            print('{0:.0f}*{1:.0f}={2:.0f}\t'.format(j,i,i*j),end=" ")
            #print("%d*%d=%d\t"%(j,i,i*j),end=" ")
    print(" ")

试题4:

def profit(I):
    c=10000
    I /= c;
    if I<=10:
        return I*0.1*c
    elif I>10 and I<=20:
        return (1+(I-10)*0.075)*c
    elif I>20 and I<=40:
        return (1.75+(I-20)*0.05)*c
    elif I>40 and I<=60:
        return (2.75+(I-40)*0.03)*c
    elif I>60 and I<=100:
        return (3.35+(I-60)*0.015)*c
    else:
        return (3.95+(I-100)*0.01)*c
I=int(input())
pro = profit(I)
print("利润为%d元,奖金总数为%d元" %(I,pro))

试题5:

import operator
x={1:2,3:4,4:3,0:0}
sorted_x=sorted(x.items(),key=operator.itemgetter(1))
print(sorted_x)

#operator.itemgetter(1)获取对象的第一个域的值