当前位置:   article > 正文

python123.io简单编程题合集

python123.io

有些代码觉得自己写得真是很丑陋啊

第K序元素查找

lt = eval(input(""))
n = eval(input(""))
lt = sorted(lt,reverse = True)
print(lt[n-1])
  • 1
  • 2
  • 3
  • 4

字符串反码A

def func(text):
    result = []
    for c in text:
        if c.islower():
            n = chr(ord('z') - (ord(c) - ord('a')))
        elif c.isupper():
            n = chr(ord('Z') - (ord(c) - ord('A')))
        else:
            n = c
        result.append(n)
    return ''.join(result)
str = input("")
print(func(str))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

整数阶乘组合计算

n, a = eval(input())
s = 1
for i in range (1, n + 1):
    s *= i
for k in range(1,n):
    a1 = a ** k
    a2 = a ** (k+1)
    if s % a1 == 0 and s % a2 != 0:
        tem = k
print(tem)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

跳台阶

def func(n):
    if n == 1 or n == 2:
        return n
    a = 1
    b = 2 
    c = 3
    for i in range(3,n+1):
        c = a + b
        a = b
        b = c
    return c
num = eval(input(""))
print(func(num))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

大多数元素A

lt = {}
seq = eval(input(""))
for i in seq:
    lt[i] = lt.get(i,0) + 1
ret = list(d.items())
#print("ret = {}".format(ret))
ret.sort(reverse = True, key = lambda x : x[1])
Num,n = ret[0]
print(Num)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

个人所得税计算E

n = eval(input(""))
if n > 80000:
    sum = (n - 3500) * 0.45
elif n > 55000:
    sum = (n - 3500) * 0.35
elif n > 35000:
    sum = (n - 3500) * 0.3
elif n > 9000:
    sum = (n - 3500) * 0.25
elif n > 4500:
    sum = (n - 3500) * 0.1
    if sum < 0:
        sum = 0
else:
    sum = 0
print(int(sum))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

货币转换I

str = input("")
if str[0:3] in ["USD"]:
    R = eval(str[3:]) * 6.78
    print ("RMB{:.2f}".format(R))
elif str[0:3] in ["RMB"]:
    R = eval(str[3:]) / 6.78
    print("USD{:.2f}".format(R))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

括号配对检测 A

str = input("")
lt = []
for i in range(0,len(str)):
    if str[i] == '(':
        lt.append('(')
    elif str[i] == ')' and len(lt) == 0:
         print("配对不成功")
         exit()
    elif str[i] == ')':
        lt.pop()
if lt == []:
    print("配对成功")
else:
    print("配对不成功")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

n!之和

def fac(n):
    s = 1
    for i in range(1,n+1):
        s *= i
    return s
n = input("")
if n.isdigit() == False or n == '0':
    print("输入有误,请输入正整数")
    exit()
num  = eval(n)
sum = 0
for i in range(1,num+1):
    sum += fac(i)
print(sum)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/884227
推荐阅读
相关标签
  

闽ICP备14008679号