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

时间:2017-05-03 04:03:56

标签: python loops

所以这是我的代码我已经尝试了这么多的循环选项,并且似乎无法让它循环整个事情,当任何帮助将是apreciated

# 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.')

1 个答案:

答案 0 :(得分:0)

这样的模式怎么样:

while True:

    # Your code here

    if enter_more_data == 'N':
        break