2017-05-03 37 views
-2

因此,這裏是我的代碼,香港專業教育學院嘗試了許多圈的選擇,只是不能似乎得到它的循環,整個事情的時候任何幫助將apreciated我想簡單的是或否循環添加到我的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.') 
+0

我發現很難找到一個問題。一個簡單的Y(N)N(o)循環究竟是什麼意思,並且是證明你的問題所需的所有代碼? –

+0

你是指一個函數? http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/functions.html – ti7

+0

這是一個可怕的設計。通過在終端上鍵入學生標記來逐個輸入學生標記是瘋狂的:這是一項緩慢而煩人的工作,有很大的錯字改變標記的機會。 – innisfree

回答

0

如何像這樣的模式:

while True: 

    # Your code here 

    if enter_more_data == 'N': 
     break 
相關問題