我想在python代码中添加一个简单的Y或N循环

2024-04-26 13:16:43 发布

您现在位置:Python中文网/ 问答频道 /正文

所以这是我的代码,我尝试了这么多的循环选项,只是似乎不能让它循环整个事情时,任何帮助将是一个赞赏

# Displays the Program Header
print('----------------------------------------------------------------------')
print('The Innovation University of Australia (IUA) Grade System')
print('----------------------------------------------------------------------')

# These print commands display the spaces to divide the sections
print()

# Asks the lecturer to input all marks out of 100
print('Please enter all marks out of 100.')

#Asks to input stydents ID and name
#Asks the to input the marks for Assignment 1 and Assignment 2
# and the Final Exam and stores them as floats
studentID = input('Please enter the student ID: ')
studentname = input('Please enter the student name: ')
assignment1 = float(input('Please enter the marks for Assignment 1: '))
assignment2 = float(input('Please enter the marks for Assignment 2: '))
final_exam = float(input('Please enter the marks for the Final Exam: '))

print()

# Displays the Thank You! message
print('Thank You!')

print()

# Calculates the weighted mark for Assignment 1, Assignment 2, and the
# total weighted mark of the Assignments by mutiplying by 20% and 30%
weighted_assignment1 = 0.2 * assignment1
weighted_assignment2 = 0.3 * assignment2
total_weighted_assignments = weighted_assignment1 + weighted_assignment2

# Displays the weighted mark for Assignment 1, Assignment 2, and the total
# weighted mark of the Assignments
print('Weighted mark for Assignment 1:', int(weighted_assignment1))
print('Weighted mark for Assignment 2:', int(weighted_assignment2))
print('Total weighted mark of the assignements:', int(total_weighted_assignments))

print()

# Calculates the weighted mark for the Final Exam and the total weighted
# mark for the subject
weighted_final_exam = 0.5 * final_exam
total_weighted_subject = total_weighted_assignments + weighted_final_exam

# Displays the weighted mark of the Final Exam and the total weighted mark
# for the subject
print('Weighted mark for Final Exam is:', int(weighted_final_exam))
weightedtotal = print('Total weighted mark for the subject:', int(total_weighted_subject))

print()

# Calculates the bonus mark for the subject depending on how high the
# total mark is
if total_weighted_subject > 50 and total_weighted_subject <= 70:
    bonus_mark = (total_weighted_subject - 50) * 0.1
elif total_weighted_subject > 70 and total_weighted_subject <= 90:
    bonus_mark = (total_weighted_subject - 70) * 0.15 + 2
elif total_weighted_subject > 90 and total_weighted_subject <= 100:
    bonus_mark = (total_weighted_subject - 90) * 0.20 + 5
else:
    bonus_mark = 0

# Displays the bonus mark for the subject
print('Bonus mark:', format(bonus_mark, '.1f'))

# Calculates the total mark for the subject with the bonus mark
total_with_bonus = total_weighted_subject + bonus_mark

# Check if total mark with bonus is greater than maximum
# possible mark of 100 and if it is set to 100 and display
# total mark with bonus
if total_with_bonus > 100:
    total_with_bonus = 100
    print('Total mark with bonus:', format(total_with_bonus, '.1f'))
else:
     print('Total mark with bonus:', format(total_with_bonus, '.1f'))

print()

outFile = open("TestFile.txt", "w")
outFile.write("student \t student \t A1 \t A2 \t final \t weighted \t  weighted total\n" )
outFile.write("id \t         name \t \t                 exam \t  total \t with bonus\n")
outFile.write("-----------------------------------------------------------------------------------------------\n")
outFile.close()

content = str(studentID) + "\t" "\t" +  str(studentname) + "\t" + str(assignment1) + "\t" + str(assignment2) + "\t" + str(final_exam) + "\t" + str(weightedtotal)

outFile = open("TestFile.txt", "a")
outFile.write(content) 
outFile.close()

#Displays Goodbye. message
print('Goodbye.')

Tags: andoftheforinputwithoutfilefinal