Python基础操作题一览

目录

Low基础练习题 

1. 给出一个包含n个整数的数列,问整数a在数列中的第一次出现是第几个。 

2. A+B问题 输入A、B;输出A+B。 

3. 求水仙花数 

4. 数列排序 

5. 闰年判断 

6. 百分制转等级制 

7. 华氏温度转化为摄氏温度 

8. 输入圆的半径计算计算周长和面积 

9. 使用分支语句实现三个数排序 

10. 使用分支语句实现三个数排序(升级版) 

11. 判断三个数的状态 

12. n以内序列求和 

13. 求余数 

14. 基本语法练习之---检查变量类型 

Mid中级操作题 

1. 基础练习 数列特征 

2. 基础练习 杨辉三角形 

3. 算法训练 字符删除 

4. 算法训练 薪水计算 

5. 算法训练 明明的随机数 

6. 基础练习 时间转换 


Low基础练习题


  1. 给出一个包含n个整数的数列,问整数a在数列中的第一次出现是第几个。

a=int(input())

s=[int(i)for i in input().split()]

b=int(input())

for i in range(a):

  c=s[i]

  if b==c:

    print(i+1)

    break

if b not in s:

  print(-1)


  1. A+B问题 输入A、B输出A+B。

a,b = map(int, input().split())

print(a+b)


  1. 求水仙花数

for i in range(100,1000):

  a=i//100

  b=(i-a*100)//10

  c=i-a*100-b*10

  if i==a**3+b**3+c**3:

print(i)


  1. 数列排序

a = int(input(""))

if 1 <= a <= 200:

    list1 = sorted(list(map(int, input().split())))

#A.sort()函数 可以将列表从小到大排序

for i in list1:

    print(i,'', end='')

#end=''意思是末尾不换行,加空格


  1. 闰年判断

y=int(input())

if y>=1990 and y<=2050:

    if (y%4==0 and y%100!=0 or y%400==0):

        print("yes")

    else:

        print("no")


  1. 百分制转等级制 

s=float(input())

if s<=100 and s>=0:

    if s>=90:

        print('A')

    elif s>=80 and s<90:

        print('B')

        print('D')

    else:

        print('E')

else:

    print('Error')


  1. 华氏温度转化为摄氏温度

F=float(input())

C=(F-32)/1.8

C2=round(C,2)

print(format(C2, ".2f"))


  1. 输入圆的半径计算计算周长和面积

r=float(input())

c=2*3.1415926*r

s=3.1415926*(r**2)

print(format(c,".2f")+','+format(s,".2f"))


  1. 使用分支语句实现三个数排序

a,b,c=map(float,input().split())

a1=format(a,".2f")

b1=format(b,".2f")

c1=format(c,".2f")

L=[a1,b1,c1]

L.sort()

A=str(L[2])

B=str(L[1])

C=str(L[0])

print(A+'>='+B+'>='+C)


  1. 使用分支语句实现三个数排序(升级版)

a,b,c,d=map(float,input().split())

a1=format(a,".2f")

b1=format(b,".2f")

c1=format(c,".2f")

L=[a1,b1,c1]

L.sort()

A=str(L[2])

B=str(L[1])

C=str(L[0])

if d==1:

print(A+'>='+B+'>='+C)

elif d==-1:

print(C+'<='+B+'<='+A)

else:

print('Error')


  1. 判断三个数的状态

a,b,c=map(float,input().split())

L=[a,b,c]

L1=set(L)

if len(L1)==1:

    print(2)

if len(L1)==2:

    print(1)

if len(L1)==3:

print(0)


  1. n以内序列求和

n=int(input())

i=0

A=0

while i<n:

    i=i+1

    A=A+i

print(A)


  1. 求余数

a,b = map(int,input().split())

c=a%b

print(c)


  1. 基本语法练习之---检查变量类型

a = 100  #(整型)

b = 12.345  #(浮点型)

c = 1 + 5j  #(复数型)

d = 'hello, world'  #(字符串)

e = True   #(布尔型)

print(type(a))

print(type(b))

print(type(c))

print(type(d))

print(type(e))


Mid中级操作题


  1. 基础练习 数列特征

n=int(input())

list1=[eval(i) for i in input().rstrip().split(" ")]

print(max(list1))

print(min(list1))

print(sum(list1))


  1. 基础练习 杨辉三角形

def main():

    n=int(input())

    lst=[[1],[1,1]]

    lst1=[]

    num=2

    while num<n:

        for i in range(len(lst[num-1])):

            if i==0:

                lst1.append(1)

            else:

                s=lst[num-1][i]+lst[num-1][i-1]

                lst1.append(s)

        lst1.append(1)

        lst=lst+[lst1]

        lst1=[]

        num=num+1

    for i in range(n):

        for j in range(len(lst[i])):

            print(lst[i][j],end=' ')

        print('')   

main()


  1. 算法训练 字符删除

w=str(input())

x=str(input())

print(w.replace(x, ''))


  1. 算法训练 薪水计算

h,m=map(float,input().split())

if h<=40:

    s=h*m

if h>40:

    s1=40*m

    if h<=50:

        s2=1.5*(h-40)*m

    if h>50:

        s2=15*m+2*(h-50)*m

    s=s1+s2

print(format(s,".2f"))


  1. 算法训练 明明的随机数

n = int(input())

nums = sorted(list(set(list(map(int, input().split())))))

print(len(nums))

print(" ".join(str(i) for i in nums))


  1. 基础练习 时间转换

s=int(input())

H=int(s//3600)

M=int((s-3600*H)//60)

S=int(s-H*3600-M*60)

print('%s:%s:%s'%(H,M,S))

  1. 基础练习 字符串对比

w1=str(input())

w2=str(input())

if w1==w2:

print(2)

if w1!=w2:

if len(w1)==len(w2):

if w1.upper()==w2.upper():

print(3)

else:

print(4)

else:

print(1)

  1. 基础练习 龟兔赛跑预测

v1, v2, t, s, l = map(int, input().split())

time, s1, s2 = 0, 0, 0

while s2 < l and s1 < l:

    s1 += v1

    s2 += v2

    time += 1

    if s1 >= l or s2 >= l:

        break

    if s1 - s2 >= t:

        s1 -= s * v1

if s1 == s2:

    print("D")

elif s1 > s2:

    print("R")

else:

    print("T")

print(time)

  1. 基础练习 FJ的字符串

def Tn(n):

    if n==1:

        print('A',end='')

    else:

        Tn(n-1)

        print(chr(65+n-1),end='')

        Tn(n-1)

    return ''

n=int(input())

Tn(n)

  1. 基础练习 回形取数

m, n = map(int, input().split())

a = []

ans = []

for _ in range(m):

    a.append(list(map(int, input().split())))

while a:

    # down

    for i in range(len(a)):

        ans += [a[i].pop(0)] if a[i] else []

    # right

    ans += a.pop() if a else []

    # top

    for i in range(len(a) - 1, -1, -1):

        ans += [a[i].pop()] if a[i] else []

    # left

    ans += a.pop(0)[::-1] if a else []

print(*ans)

  1. 基础练习 Huffuman树

x=int(input())

if x>=0 & x<=100:

    list1=list(map(int,input().split()))

    list1.sort(reverse=True)

    while list1[0]>1000:

        del(list1[0])

    total=0

    while len(list1)>1:

        list1.sort(reverse=True)

        num=list1.pop()+list1.pop()

        total=total+num

        list1.append(num)

    print(total)

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值