通过判断节点ID,选择是否将其添加到SET中。
import ansafrom ansa import basefrom ansa import constantsdef 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 = 0while count < 5:print(count)count += 1
x = 10if x > 5:print("x is greater than 5")
x = 10if x > 15:print("x is greater than 15")elif x > 5:print("x is greater than 5 but not greater than 15")
x = 3if 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 = 0max_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 = scoreif score < min_score:min_score = score# 分类统计if score >= 90:grade_distribution["优秀"] += 1elif score >= 75:grade_distribution["良好"] += 1elif score >= 60:grade_distribution["及格"] += 1else: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}人")