我这个代码目的是随机输出成绩判断等级,并将结果输入到文件中,代码没问题,现在想让它每次随机输入4次,怎么添加循环,麻烦看一下,给一个修改后的代码,谢谢啦
import random
OUTPUT_FILE = 'scores.txt' # 定义文件名,可根据需求更改,这里定义文件名为 scores.txt
out_file = open(OUTPUT_FILE, 'w') # 打开文件
score = random.randint(0,100)
if 0<=score<50:
print(score,"is Bad",file=out_file)
elif 50<=score<90:
print(score,"is Pass",file=out_file)
elif 90<=score<=100:
print(score,"is Excellent",file=out_file)
out_file.close() # 关闭文件