通过判断节点ID,选择是否将其添加到SET中。
import ansa
from ansa import base
from ansa import constants
def main():
m = list()
for i in range(1,10):
if i % 2 == 0:
ent = base.GetEntity(constants.NASTRAN, "GRID", i)
m.append(ent)
print (m)
set = base.CreateEntity(constants.NASTRAN, "SET", {'Name': 'new set'})
base.AddToSet(set, m)
main ()
# 遍历列表
for item in [1, 2, 3, 4, 5]:
print(item)
for char in "Hello":
print(char)
# 使用while循环
count = 0
while count < 5:
print(count)
count += 1
x = 10
if x > 5:
print("x is greater than 5")
x = 10
if x > 15:
print("x is greater than 15")
elif x > 5:
print("x is greater than 5 but not greater than 15")
x = 3
if x > 5:
print("x is greater than 5")
else:
print("x is not greater than 5")
# 使用for循环和if语句
for i in range(1, 11): # range(1, 11)生成从1到10的数字
if i % 2 == 0:
print(f"{i} is even")
else:
print(f"{i} is odd")
# 学生分数列表
scores = [76, 85, 90, 67, 59, 72, 88, 99, 55, 70]
# 初始化变量
total_score = 0
max_score = scores[0]
min_score = scores[0]
grade_distribution = {"优秀": 0, "良好": 0, "及格": 0, "不及格": 0}
# 使用for循环处理分数
for score in scores:
# 累加总分
total_score += score
# 更新最高分和最低分
if score > max_score:
max_score = score
if score < min_score:
min_score = score
# 分类统计
if score >= 90:
grade_distribution["优秀"] += 1
elif score >= 75:
grade_distribution["良好"] += 1
elif score >= 60:
grade_distribution["及格"] += 1
else:
grade_distribution["不及格"] += 1
# 计算平均分
average_score = total_score / len(scores)
# 打印结果
print(f"平均分: {average_score}")
print(f"最高分: {max_score}")
print(f"最低分: {min_score}")
print("成绩分布:")
for grade, count in grade_distribution.items():
print(f"{grade}: {count}人")