目录
1. 给出一个包含n个整数的数列,问整数a在数列中的第一次出现是第几个。
Low基础练习题
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)
a,b = map(int, input().split())
print(a+b)
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)
a = int(input(""))
if 1 <= a <= 200:
list1 = sorted(list(map(int, input().split())))
#A.sort()函数 可以将列表从小到大排序
for i in list1:
print(i,'', end='')
#end=''意思是末尾不换行,加空格
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")
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')
F=float(input())
C=(F-32)/1.8
C2=round(C,2)
print(format(C2, ".2f"))
r=float(input())
c=2*3.1415926*r
s=3.1415926*(r**2)
print(format(c,".2f")+','+format(s,".2f"))
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)
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')
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)
n=int(input())
i=0
A=0
while i<n:
i=i+1
A=A+i
print(A)
a,b = map(int,input().split())
c=a%b
print(c)
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中级操作题
n=int(input())
list1=[eval(i) for i in input().rstrip().split(" ")]
print(max(list1))
print(min(list1))
print(sum(list1))
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()
w=str(input())
x=str(input())
print(w.replace(x, ''))
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"))
n = int(input())
nums = sorted(list(set(list(map(int, input().split())))))
print(len(nums))
print(" ".join(str(i) for i in nums))
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))
- 基础练习 字符串对比
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)
- 基础练习 龟兔赛跑预测
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)
- 基础练习 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)
- 基础练习 回形取数
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)
- 基础练习 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)