0% found this document useful (0 votes)
10 views

Python

This Python experiment aims to teach students basic Python operations and code comprehension skills. It includes 6 practice tests covering topics like tax calculation, digit extraction, average and sum calculation, chicken-rabbit problems, the Collatz conjecture, and blood pressure classification. The document provides sample code and instructions for students to complete the tests and improve their Python coding and debugging abilities.

Uploaded by

LKKKLKKK
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python

This Python experiment aims to teach students basic Python operations and code comprehension skills. It includes 6 practice tests covering topics like tax calculation, digit extraction, average and sum calculation, chicken-rabbit problems, the Collatz conjecture, and blood pressure classification. The document provides sample code and instructions for students to complete the tests and improve their Python coding and debugging abilities.

Uploaded by

LKKKLKKK
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

一、实验名称

Python 实验课

二、实验目的
引导学生学会 py 的基础操作,能够编写基础代码,并且有代码解读的能力

三、实验内容与步骤
1.第一次测验
爸爸交税:
x =int(input(""))
y=x-2000
if y-10000>0:
w = (y - 10000)*(1-0.1)
else: w=0
if y-5000>0:
if y>10000:
q=5000*(1-0.05)
else:q =(y-5000)*(1-0.05)
else: q=0
if y<5000:
b =y
else: b=5000
z =int(w+q+b)
print(z)
2. 每一位是几
x=eval(input(""))
for i in range(8):
y=x%10
print(y)
x=x//10

3. 求整数和与均值
n = eval(input())
sum = 0
for i in range(1,n+1):
num = eval(input())
sum = sum + num
print("{} {:.2f}".format(sum,sum/n))
4.鸡兔同笼
zhi =eval(input(""))
jiao=eval(input(""))
if jiao%2==1:
print("-1")
print(' ')
print("-1")
else:
tu = int(jiao/2-zhi)
ji= int(zhi-tu)
if tu<0 or ji<0:
print("-1")
print(' ')
print("-1")
else:
print(ji)
print(' ')
print(tu)
4. 冰雹谷猜想
n = int(input())
a = 0
while n != 1:
if n % 2 == 0:
n /= 2
else:
n = n * 3 + 1
a += 1
print(a)

5.游戏手柄
a = int(input(''))
b = int(input(''))
if a == 1 and b != 1:
print("attack")
elif b == 1 and a != 1:
print("jump")
elif a != 1 and b != 1:
print("idle")
else:
print("bomb")

5. 正常血压.
n = int(input())
a = 0
b = 0
for i in range(n):
h = input().split()
if 90 <= int(h[0]) <=140 and 60<= int(h[1]) <= 90:
a += 1
if b <= a:
b = a
else:
a = 0
print(b)
6. 字符图形
x=eval(input(""))
for i in range(x):
y = " "*i+"*"*((x-1-i)*2+1)
print(y)

第二次测验:
1. 爬楼梯
def fib(n):
if n == 0 or n == 1:
return 1
else:
return fib(n - 1) + fib(n - 2)

a = int(input())
print(fib(a))
2. 奥运会奖牌计数
n = int(input())
a = b = c = 0
for i in range(n):
s = input().split()
a += int(s[0]) # a:金牌数
b += int(s[1]) # b:银牌数
c += int(s[2]) # c:铜牌数
total = a+b+c
print(a,b,c,total,end="")

3. 谁的身高超过平均值
x=eval(input(""))
n=0
m=0
s=""
z =input("")
h = input().split()
if x>1 and x<11:
for i in range(x):
n += int(h[i])
n = n // x
i = 0
for i in range(x):
if int(h[i]) >= n:
m+=1
if m==1:
s += str(i + 1) + ":" + h[i]
else:
s +=' '+ str(i + 1) + ":" + h[i]
print('AV=%d' % n)
print("")
print(s)

4. 团体赛
n = int(input())
a = input().split()
b = int(min(a))
if b >= 80:
print('advanced')
else:
print('knocked out')
5. 药房管理
m=int(input())
n=int(input())
count=0
a=list(map(int,input().split()))
for i in a:
if i<=m:
count +=1
m=m-i
print(n-count)

6. 整数序列的元素最大跨度值
n = input()
s = input().split()
maxc = minc = int(s[0])
for x in s:
maxc = max(maxc,int(x))
minc = min(minc,int(x))
print(maxc-minc)

3. 第三次
1.B
X = []
Y = []

for i in range(0, 100):


for j in range(2, i):
if i % j == 0:
break
else:
X.append(i)

for i in range(0, 101):


if i % 2 == 0:
Y.append(i)

for i in Y:
for m in X:
for n in X:
if i == m + n:
print(i, '', '=', '', m, '+', n)
2.C
n=int(input(""))
a=list(map(int,input().split()))
def fib(n):
return a%10+(a-a%10)/10
for i in range()

3.D
a = 0
b = 0
for i in range(5):
n = int(input())
a += n
b += a
print(b)

4.E
n = int(input())
hours = ''
minutes = ''
seconds = ''
h = n // 3600
m = n % 3600 // 60
s = n % 60
if h == 0:
pass
elif h == 1:
hours = '1hour'
else:
hours = '%dhours' % h

if m == 0:
pass
elif m == 1:
minutes = '1minute'
else:
minutes = '%dminutes' % m

if s == 0:
pass
elif s == 1:
seconds = '1second'
else:
seconds = '%dseconds' % s
if n == 1:
t = '%dsecond=' % n + hours + minutes + seconds
if n > 1:
t = '%dseconds=' % n + hours + minutes + seconds
print(t)

5.F
x = float(input())
a = 2
y = 0
def fib(n):
return a * 0.98**n
for n in range(10000):
y = y + fib(n)
if y > x:
print(n+1)
Break
4. 第四次
1. 成绩分类统计
a = 0
b = 0
c = 0
d = 0
for i in range(1,10000):
x = eval(input("Input No.{}'s score:".format(i)))
if x >= 90:
a += 1
elif x >= 75:
b += 1
elif x >= 60:
c += 1
elif x >= 0:
d += 1
elif x == -1:
break
print('A:{}'.format(a))
print('B:{}'.format(b))
print('C:{}'.format(c))
print('D:{}'.format(d))
2. 满足的条件数累加
a = input().split()
sum = 0
for i in range(int(a[0]),int(a[1])+1):
if i % 17 == 0:
sum += i
print(sum)

3. 水仙花数
x=eval(input(""))

def sx(n):
s=0
z=n
for y in range(3):
m = z % 10
s += m ** 3
z = z // 10
if n==s:
return True
else:return False
g=0
for i in range(100,x+1):
if sx(i):
g+=1
print(g)

4. 寻找支撑数

m = int(input())
n = input().split()
for i in range(1,m-1):
if int(n[i]) > int(n[i+1]) and int(n[i]) > int(n[i-1]):
print(n[i])
5. 第五次
1. A
n = int(input())
c = []
for i in range(0, n):
a, b = map(int, input().split())
x = b / a
c.append(x)
for j in range(1, len(c)):

if c[0] - c[j] > 0.05:


print("worse")
elif c[j] - c[0] > 0.05:
print("better")
else:
print("same")
2. B
def f(A):
if A == 0:
return 50000
else:
return (f(A - 1) + 10000) * 1.005
B = int(input())
print('{:.2f}'.format(f(B)))

3. C
a = int(input())
if a <= 1000:
print(8)
else:
b = 0
while a > 1000:
a -= 500
b += 1
print(8 + 4 * a)

4. D
n = int(input())
a = input().split()
jishu = ''
oushu = ''
for i in range(n):
if int(a[i]) % 2 == 0:
oushu += a[i] + ' '
else:
jishu += a[i] + ' '
jishu = jishu[0:-1]
oushu = oushu[0:-1]
print(jishu)
print(oushu)
5. E
str1 = '01234'
str2 = input()
a = 0
if len(str1) == len(str2):
for s1, s2 in zip(str1, str2):
if s1 == s2:
a += 1
b = 100 * a / len(str1)
print('{:.2f}%'.format(b))
else:
print('密码长度不匹配')
四、实验小结

此次学习 python 让我学会了基础的编程能力以及分析程序的能力并

且我相信在未来的学习中,我会把 py 和工业工程的基础法结合在一

起,发挥相当的作用。

You might also like