Python实验心得5.0
实验过程
(1)用if-elif判断
(2)用if-elif判断
(3)用if-elif判断
(4)用if-elif判断
(5)输入一个字符串将四种类型桶排到char_count元组中并输出
(6)输入行和列,用随机数种子生成随机数,控制行和列的输出
(7)利用素数本身的特性在3~sqrt(x)中如果没有取余为0的则是,否则反之
(8)控制列j每次都小于等于行i。
(9)for循环求1~100的和
(10)控制行和列的输入和输出,输出注意换行
#1
x = eval(input("输入一个年份: "))
if x % 400==0 or (x%4==0 and x%100!=0):
print("闰年")
else :
print("不是闰年")
#2
if x < 0 or x >= 20:
y = 0
elif 0 <= x < 5:
y = x
elif 5 <= x < 10:
y = x * 3 - 5
elif 10 <= x < 20:
y = x * 0.5 - 2
print(y)
#3
x = eval(input("请输入x轴上的点: "))
y = eval(input("请输入y轴上的点: "))
if x == 0:
print("在y轴上")
if y == 0:
print("在x轴上")
if x > 0 and y > 0:
print("点", x, y, "在第一象限")
elif x < 0 and y > 0:
print("点", x, y, "在第二象限")
elif x < 0 and y < 0:
print("点", x, y, "在第三象限")
elif x > 0 and y < 0:
print("点", x, y, "在第四象限")
#4
per_num = int(eval(input("请输入乘坐人数: ")))
sta_num = int(eval(input("请输入乘坐站数: ")))
if 0 >= per_num or 0 >= sta_num:
print("error")
else:
if 1 <= sta_num <= 4:
print("乘坐地铁需要的总金额", per_num * 3)
elif 5 <= sta_num <= 9:
print("乘坐地铁需要的总金额", per_num * 4)
else:
print("乘坐地铁需要的总金额", per_num * 5)
#5
st = input("输入一个字符串: ")
char_count = {"big_char": 0,"small_char": 0,"digit": 0,"other_char": 0}
for i in st:
if i.isdigit():
char_count["digit"] += 1
elif 'A' <= i <= 'Z':
char_count["big_char"] += 1
elif 'a' <= i <= 'z':
char_count["small_char"] += 1
else:
char_count["other_char"] += 1
print(char_count)
#6
import numpy as np
import random
line = eval(input("请输入行数:"))
list_1 = eval(input("请输入列数:"))
array = np.random.randint(1, 100, list_1 * line, int).reshape(line, list_1)
print(array)
#7
data = eval(input("请输入一个数:"))
if data < 3 and data > 0:
print("素数")
for i in range(2, int(data ** 0.5) + 1):
if data % i == 0:
print("不是素数")
exit()
else:
print("是素数")
#8
for i in range(1,10):
for j in range(1,i+1):
print(i,"*",j,"=",i*j,end="\t")
print()
#9
print("1~100的和: ")
sum = 0
list = [i * 1 for i in range(1, 101)]
for i in range(1, 101):
sum += i
for j in range(0, 100):
if j != 99:
print(list[j], '+', end=" ")
else:
print(list[j], "=", sum)
# print()
print(sum)
#10
#(1)
for i in range(4):
for j in range(7):
print("*",end="")
print()
#(2)
for i in range(4):
for j in range(i*2+1):
print("*",end="")
print()
#(3)
for i in range(1, 5):
for j in range(4, i, -1):
print(" ", end="")
for k in range(i * 2 - 1):
print("*", end="")
print()
#(4)
for i in range(4,0,-1):
for j in range(i,4):
print(" ",end="")
for k in range(i*2-1):
print("*", end="")
print()
#(5)
for i in range(4):
for j in range(i*2+1):
print("*",end="")
print()
for i in range(3,0,-1):
for j in range(i*2-1):
print("*",end="")
print()
#(6)
for i in range(1,5):
for j in range(4,i,-1):
print(" ",end="")
for k in range(i*2-1):
print("*",end="")
print()
for i in range(3,0,-1):
for j in range(i,4):
print(" ",end="")
for k in range(i*2-1):
print("*", end="")
print()
1
2
3
4
5
6
7
8
9
10(1)
10(2)
10(3)
10(4)
10(5)
10(6)