python123.io简单编程题合集

Posted 只是有点小怂

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python123.io简单编程题合集相关的知识,希望对你有一定的参考价值。

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

第K序元素查找

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

字符串反码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))

整数阶乘组合计算

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)

跳台阶

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))

大多数元素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)

个人所得税计算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))

货币转换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))

括号配对检测 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("配对不成功")

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)

以上是关于python123.io简单编程题合集的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode小白入门——简单题目八题合集,每题两解

求解一道Python编程题(求代码)

Python和Java编程题

C语言编程题 从100-999之间输入1个数,如果这个数的个位十位百位之和大于10,则输出这个数,否则输出10

这个疯子整理的十万字Java面试题汇总,终于拿下40W offer!(JDK源码+微服务合集+并发编程+性能优化合集+分布式中间件合集)

Python面试合集 史上最全面Python面试题和详解(10套) 完整版