Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I need help with the below code please, I am trying to create a piece of code that displays true or false at the beginning with a given course code using a function. four letters, 3 digits, and a 'space' in between them if that condition is true then the program will ask the user to choose the menu with 6 options using a dictionary. please explain to me where did I go wrong.

Thank you

What I have tried:

Python
def CourseCode(input_word):
            COURSES = ['SCIN', 'ENGG', 'MATC', 'BCSE', 'BCMS', 'ENGS', 'MGMT', 'COMM']
            VALID_DIGITS = (1, 2, 3, 4, 6)   
            if user_code == 'SCIN 123':
                 return True
            else:
                 return  False  

def user_menu():
            add_course = {}
            add_course['1'] ="Add new Course:"
            add_course[True] = "Course added"
            add_course[False]= "Invalid course code: The format is XXXX 111"
            list_course = {}
            list_course['2'] = "List Course:"
            print("SCIN 123", "ENGG 101", "MATC 354", "MATC 355", "BCSE 202", "CCMS 100", "ENGS 202" )
            stu_enrol = {}
            stu_enrol['3'] = "Enrol Student"
            stu_enrol = input("Please enter student family name: ")
            stu_enrol[new_student]=[]
            print(stu_enrol)
            stu_enrol = input(f"Please enter student first initial {new_student}: ")
            stu_enrol = input(f"Please enter course to enrol or X to finish {new_student}: ")
            if key_data in stu_enrol:
                 print("Successfully enrolled.")
                 elif(key_data != add_course ):
                 print("Sorry you need to enrol in at least two courses")
                 elif(key_data != stu_enrol):
                 print("Sorry, already enrolled in that course")
                 elif(key_data != CourseCode):
                 print("Sorry, that course does not exist.")
                 else:
                 print("Sorry, a maximum of four courses are allowed")
            lis_enr_stu = {}
            lis_enr_stu['4']={"List Enrolments for a Student"}
            lis_all_enr = {}
            lis_all_enr['5']={"List all Enrolments"}
            user_exit['6'] = "Quit"
            if action() is False:
                  break

    input_word = input("Please select menu choice: ")
     CourseCode = CourseCode(input_word)
Posted
Updated 24-Dec-20 6:22am
v8
Comments
Richard MacCutchan 24-Dec-20 6:20am    
You need to correct your indentation.

1 solution

Quote:
please explain to me where did I go wrong.

The problem is that you need to learn Python syntax.
This just doesn't exist:
Python
if key_data in stu_enrol:
     print("Successfully enrolled.")
     elif: # something missing here
          print("Sorry you need to enrol in at least two courses")
     elif: # something missing here
          print("Sorry, already enrolled in that course")
     elif: # something missing here
          print("Sorry, that course does not exist.")
     else:
          print("Sorry, a maximum of four courses are allowed")

[Update]
Your updated code is better, but there is still a huge error:
replace
Python
if key_data in stu_enrol:
     print("Successfully enrolled.")
     elif(key_data != add_course ):
          print("Sorry you need to enrol in at least two courses")
     elif(key_data != stu_enrol):
          print("Sorry, already enrolled in that course")
     elif(key_data != CourseCode):
          print("Sorry, that course does not exist.")
     else(key_data != max):
          print("Sorry, a maximum of four courses are allowed")

with
Python
if key_data in stu_enrol:
     print("Successfully enrolled.")
elif(key_data != add_course ):
     print("Sorry you need to enrol in at least two courses")
elif(key_data != stu_enrol):
     print("Sorry, already enrolled in that course")
elif(key_data != CourseCode):
     print("Sorry, that course does not exist.")
else(key_data != max): # there must be nothing with the else
     print("Sorry, a maximum of four courses are allowed")
 
Share this answer
 
v3
Comments
Richard MacCutchan 24-Dec-20 3:59am    
Slight problem with the else clause.
Patrice T 24-Dec-20 4:02am    
Indeed, I missed this 1 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900