Python Forum
invalid syntax in my program, really doing my head in!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
invalid syntax in my program, really doing my head in!
#1
Hi all,

I'm writing a code for uni and i keep getting an invalid syntax error in my code, i've done it to textbook spec but i'm still having errors,, can someone look over it and see what the issue is. I've put in Exclamation for the invalid syntax error line
def main():         UniInfo()                  startFile = open('IUA.txt', 'a')         startFile.write('\n'"Student \t Student \t A1 \t A2 \t Final \t Weighted Total"'\n')         startFile.write('\n'"ID \t \t Name \t \t \t \t Exam \t with Bonus"'\n')         startFile.write('\n'"---------------------------------------------------------------------------"'\n')                  Hapkido = True         # The program is displaying the first question to enter all marks out of 100.              print("Please enter all marks out of 100")         # The program is now asking marks for all the Assignments and Final exam marks to be inputted make note they need to be exactly entered even if its a long decimal number.         # The program will then print "Thank you!" after you have inputted all of the data.         # The program also has a "ValueError" message so if there's any negative numbers entered the program will crash and show the error message of what the inputter did wrong.         Error = ValueError("No negative numbers only 0 and above please")         Student_ID = input("Please enter the student ID: ")         Student_name = input("Please enter the student name: ")         Assignment_1 = float(input("Please enter the marks for Assignment 1: "))         if Assignment_1 < 0:                 raise Error         Assignment_2 = float(input("Please enter the marks for Assignment 2: "))         if Assignment_2 < 0:                 raise Error         Final_Exam = float(input("Please enter the marks for the Final Exam: "))         if Final_Exam < 0:                 raise Error                 print("Thank You!")         # The program is now calculating the assignment marks and Final Exam mark into a weighted mark.         # It is taking the inputted number from before and multiplying it by 0.2, 0.3 or 0.5 where applicable transforming it to a weighted mark for the next section of the program.         Weighted_Assignment_1 = float(Assignment_1 * 0.2)         Weighted_Assignment_2 = float(Assignment_2 * 0.3)         Final_Exam_Weighted_mark = float(Final_Exam * 0.5)         # The program is displaying the results of the weighted assignment marks calculated from before.         # This is then shown as an output.         print("Weighted marks for Assignment 1:", Weighted_Assignment_1)         print("Weighted marks for Assignment 2:", Weighted_Assignment_2)         # The program is now showing the output of Assignment 1 and 2 by adding them together.         # This then displays the total weighted assignment mark as a new variable.         Total_Assignment_mark = float(Weighted_Assignment_1 + Weighted_Assignment_2)         print("Total weighted mark of the assignments:", Total_Assignment_mark)         # The program is also showing output of the Final Exam Weighted mark.         # The program is showing the output of Final Exam Weighted mark and Total Assignment mark by adding them together.         print("Weighted mark for Final Exam:", Final_Exam_Weighted_mark)         Total_Weighted_mark = float(Final_Exam_Weighted_mark + Total_Assignment_mark)         # This then displays the Total Weighted mark math from the new variable.         print("Total weighted mark for the subject:", Total_Weighted_mark)         # This section is the new part of AI2 we are now adding the Assignments 1 and 2 and Final Exam weighted mark together and adding a bonus mark.         # The program displays the output below which is an ugly long decimal if its a long decimal number inputted.         # This section now starts the new part of the new variables which are made up of the AI2 "Bonus Policy Table" math configuration.         # This is worked out by the Total Weighted mark minus the minimum mark of the particular bonus policy table range and then multiplied by a percentage then a bonus mark added on if applicable.         # Each bonus section has different formulas to suit the Total weighted mark.          Ten_Percent = float((Total_Weighted_mark - 50) * 0.1)         Fifteen_Percent = float((Total_Weighted_mark - 70) * 0.15)         Fifteen_Percent_2 = float(Fifteen_Percent + 2)         Twenty_Percent = float((Total_Weighted_mark - 90) * 0.2)         Twenty_Percent_2 = float(Twenty_Percent + 5)         # This section of the program shows the if statements and depending on the Total Weighted mark it will run to that "if statement" section.         # Once this is done the Bonus mark calculated before will be run to the particular "if statement" section as needed depending on how big Total Weighted mark is and what "if statement" section is run.         if Total_Weighted_mark<=50:                 if Total_Weighted_mark<=50:                         print("Bonus mark: nil")              if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                 if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                         print("Bonus mark:", Ten_Percent)                 else:                         print("Bonus mark: nil")              if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                 if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                         print("Bonus mark:", Fifteen_Percent_2)                 else:                         print("Bonus mark: nil")              if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                 if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                         print("Bonus mark:", Twenty_Percent_2)                 else:                         print("Bonus mark: nil")              if Total_Weighted_mark>100:                 if Total_Weighted_mark>100:                         print("Bonus mark: nil")         # New variables have been created to add the Total Weighted marks and the Bonus marks from the previous section of the program.          # This second last section the program shows the if statements and depending on the Total Weighted mark it will run to that "if statement" section.         # The program then displays the new variable which is the math plus the bonus mark, depending on the Total weighted mark it will run to that "if" section and display the new math result.         No_Bonus = float(Total_Weighted_mark + 0)         Ten_Percent_Bonus = float(Total_Weighted_mark + Ten_Percent)         Fifteen_Percent_Bonus = float(Total_Weighted_mark + Fifteen_Percent_2)         Twenty_Percent_Bonus = float(Total_Weighted_mark + Twenty_Percent_2)         if Total_Weighted_mark<=50:                 print("Total mark with bonus: %.2f" % No_Bonus)                  if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                 print("Total mark with bonus: %.2f" % Ten_Percent_Bonus)         if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                 print("Total mark with bonus: %.2f" % Fifteen_Percent_Bonus)         if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                 print("Total mark with bonus: %.2f" % Twenty_Percent_Bonus)                    if Total_Weighted_mark>100:                 print("Total mark with bonus: %.2f" % No_Bonus)                          # While loop is now asking to continue                          loop = input("Do you want to enter marks for another student (Y/N)?: ")         while Hapkido:                 if loop == "Y":                                 # The program is displaying the first question to enter all marks out of 100.                                      print("Please enter all marks out of 100")                                 # The program is now asking marks for all the Assignments and Final exam marks to be inputted make note they need to be exactly entered even if its a long decimal number.                                 # The program will then print "Thank you!" after you have inputted all of the data.                                 # The program also has a "ValueError" message so if there's any negative numbers entered the program will crash and show the error message of what the inputter did wrong.                                 Error = ValueError("No negative numbers only 0 and above please")                                 function = input("Please enter the student ID: ")                                 input("Please enter the student name: ")                                 Assignment_1 = float(input("Please enter the marks for Assignment 1: "))                                 if Assignment_1 < 0:                                         raise Error                                 Assignment_2 = float(input("Please enter the marks for Assignment 2: "))                                 if Assignment_2 < 0:                                         raise Error                                 Final_Exam = float(input("Please enter the marks for the Final Exam: "))                                 if Final_Exam < 0:                                         raise Error                                         print("Thank You!")                                                  # The program is now calculating the assignment marks and Final Exam mark into a weighted mark.                                 # It is taking the inputted number from before and multiplying it by 0.2, 0.3 or 0.5 where applicable transforming it to a weighted mark for the next section of the program.                                 Weighted_Assignment_1 = float(Assignment_1 * 0.2)                                 Weighted_Assignment_2 = float(Assignment_2 * 0.3)                                 Final_Exam_Weighted_mark = float(Final_Exam * 0.5)                                 # The program is displaying the results of the weighted assignment marks calculated from before.                                 # This is then shown as an output.                                 print("Weighted marks for Assignment 1:", Weighted_Assignment_1)                                 print("Weighted marks for Assignment 2:", Weighted_Assignment_2)                                 # The program is now showing the output of Assignment 1 and 2 by adding them together.                                 # This then displays the total weighted assignment mark as a new variable.                                 Total_Assignment_mark = float(Weighted_Assignment_1 + Weighted_Assignment_2)                                 print("Total weighted mark of the assignments:", Total_Assignment_mark)                                 # The program is also showing output of the Final Exam Weighted mark.                                 # The program is showing the output of Final Exam Weighted mark and Total Assignment mark by adding them together.                                 print("Weighted mark for Final Exam:", Final_Exam_Weighted_mark)                                 Total_Weighted_mark = float(Final_Exam_Weighted_mark + Total_Assignment_mark)                                 # This then displays the Total Weighted mark math from the new variable.                                 print("Total weighted mark for the subject:", Total_Weighted_mark)                                 # This section is the new part of AI2 we are now adding the Assignments 1 and 2 and Final Exam weighted mark together and adding a bonus mark.                                 # The program displays the output below which is an ugly long decimal if its a long decimal number inputted.                                 # This section now starts the new part of the new variables which are made up of the AI2 "Bonus Policy Table" math configuration.                                 # This is worked out by the Total Weighted mark minus the minimum mark of the particular bonus policy table range and then multiplied by a percentage then a bonus mark added on if applicable.                                 # Each bonus section has different formulas to suit the Total weighted mark.                                  Ten_Percent = float((Total_Weighted_mark - 50) * 0.1)                                 Fifteen_Percent = float((Total_Weighted_mark - 70) * 0.15)                                 Fifteen_Percent_2 = float(Fifteen_Percent + 2)                                 Twenty_Percent = float((Total_Weighted_mark - 90) * 0.2)                                 Twenty_Percent_2 = float(Twenty_Percent + 5)                                 # This section of the program shows the if statements and depending on the Total Weighted mark it will run to that "if statement" section.                                 # Once this is done the Bonus mark calculated before will be run to the particular "if statement" section as needed depending on how big Total Weighted mark is and what "if statement" section is run.                                 if Total_Weighted_mark<=50:                                         if Total_Weighted_mark<=50:                                                 print("Bonus mark: nil")                                      if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                                         if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                                                 print("Bonus mark:", Ten_Percent)                                         else:                                                 print("Bonus mark: nil")                                      if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                                         if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                                                 print("Bonus mark:", Fifteen_Percent_2)                                         else:                                                 print("Bonus mark: nil")                                      if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                                         if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                                                 print("Bonus mark:", Twenty_Percent_2)                                         else:                                                 print("Bonus mark: nil")                                      if Total_Weighted_mark>100:                                         if Total_Weighted_mark>100:                                                 print("Bonus mark: nil")                                 # New variables have been created to add the Total Weighted marks and the Bonus marks from the previous section of the program.                                  # This second last section the program shows the if statements and depending on the Total Weighted mark it will run to that "if statement" section.                                 # The program then displays the new variable which is the math plus the bonus mark, depending on the Total weighted mark it will run to that "if" section and display the new math result.                                 No_Bonus = float(Total_Weighted_mark + 0)                                 Ten_Percent_Bonus = float(Total_Weighted_mark + Ten_Percent)                                 Fifteen_Percent_Bonus = float(Total_Weighted_mark + Fifteen_Percent_2)                                 Twenty_Percent_Bonus = float(Total_Weighted_mark + Twenty_Percent_2)                                 if Total_Weighted_mark<=50:                                         print("Total mark with bonus: %.2f" % No_Bonus)                                          if Total_Weighted_mark>50 and Total_Weighted_mark<=70:                                         print("Total mark with bonus: %.2f" % Ten_Percent_Bonus)                                 if Total_Weighted_mark>70 and Total_Weighted_mark<=90:                                         print("Total mark with bonus: %.2f" % Fifteen_Percent_Bonus)                                 if Total_Weighted_mark>90 and Total_Weighted_mark<=100:                                         print("Total mark with bonus: %.2f" % Twenty_Percent_Bonus)                                            if Total_Weighted_mark>100:                                         print("Total mark with bonus: %.2f" % No_Bonus)                                                                          loop = input("Do you want to enter marks for another student (Y/N)?: ")                                                          elif loop == "N":                         print("Goodbye")                         Hapkido = False                 else:                         loop = input("Do you want to enter marks for another student (Y/N)?: ")                                  startFile = open('IUA.txt', 'w')         startFile.write(str(Student_ID + '\n' + Total_Weighted_mark)         **exclamation** **exclamation** **exclamation** **exclamation** startFile.close() def UniInfo():         print("-----------------------------------------------------------------------------------------")         print("The Innovation University of Australia (IUA) Grade System")         print("-----------------------------------------------------------------------------------------")                                  main()
Reply
#2
Are you not missing a ")" on the line before the syntax error

startFile.write(str(Student_ID + '\n' + Total_Weighted_mark)

Bass

"The good thing about standards is that you have so many to choose from" Andy S. Tanenbaum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 944 Apr-13-2025, 05:50 AM
Last Post: Winfried
  print(data) is suddenly invalid syntax db042190 6 4,970 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  numpy.array has no attribute head Led_Zeppelin 1 4,525 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Cannot get output for df.head() Led_Zeppelin 0 2,433 Jun-28-2022, 02:15 PM
Last Post: Led_Zeppelin
  SyntaxError: invalid syntax ?? korenron 15 11,607 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 21,709 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 4,239 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 4,942 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 7,137 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  [split] SyntaxError: invalid syntax Code_X 3 4,386 May-04-2021, 05:15 PM
Last Post: Yoriz

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.