2016-12-08 3 views
0
import Course 
import Person 
import Student 


CREATE = 1 
ADD_STUDENTS = 2 
COURSE_INFO = 3 
ADD_SCORES = 4 
QUIT = 5 


def main(): 

    choice = 0 

    while choice != QUIT: 
    choice = get_menu_choice() 

    if choice == CREATE: 
     add_Course() 
    elif choice == ADD_STUDENTS: 
     add_Student() 
    elif choice == COURSE_INFO: 
     view_Course() 
    elif choice == ADD_SCORES: 
     add_Scores() 
    elif choice == QUIT: 
     quit() 



def get_menu_choice(): 
    print() 
    print(" Welcome to CourseAware's Faculty Menu") 
    print('---------------------------') 
    print('1. Create Course ') 
    print('2. Add Students to a Course') 
    print('3. View Course Information') 
    print('4. Add Test scores to a Course') 
    print('5. Exit') 
    print() 

choice = int(input('Enter your choice: ')) 

while choice < CREATE or choice > QUIT: 
    choice = int(input('Enter a valid choice: ')) 

return choice 

이 영역에 문제가 있습니다. 나는 사용자에게 코스를 만들 것을 요청하고 싶다. 정보를 추가하고 나면 옵션 3에 정보를 보내고 싶습니다.범위 밖의 파이썬 인쇄?

데프 add_Course() : 사용자가 새로운 과정을 상자에 포장, 그는 내가이 add_Course 옵션에 입력 한 정보를 인쇄 할 그것을 볼 수 선택 그래서 일단

name = input("Enter course name: ") 
    number = input("Enter course number: ") 
    units = input("Enter courses units: ") 
    instructor = input("Enter courses Instructor: ") 
    myCourse = Course.Course(name,number,units,instructor) 

    print("Courses' Name: ",myCourse.getName()) 
    print("Courses' Number: ",myCourse.getNumber()) 
    print("Courses' Units: ",myCourse.getUnits()) 
    print("Courses' Instructor: ",myCourse.getInstructor()) 
    print("Course Added!") 
    return myCourse 

def add_Student(): 
    Name = input("Enter First and Last Name of Sudent: ") 
    Status = input("Enter Status of Stdent: ") 
    GPA = input("Enter Students GPA: ") 
    newStudent = Student.Student(Name, Status, GPA) 

    print("Student' First Name: ",newStudent.getName()) 
    print("Student' Status: ",newStudent.getStatus()) 
    print("Student' Instructor: ",newStudent.getGPA()) 


    infile = open('student.txt','a') 
    infile.write('\n') 
    infile.write(newStudent) 

. 데프 view_Course() :

print("Courses' Name: ",myCourse.getName()) 
    print("Courses' Number: ",myCourse.getNumber()) 
    print("Courses' Units: ",myCourse.getUnits()) 
    print("Courses' Instructor: ",myCourse.getInstructor()) 

주()

감사 의견은 환영합니다!

+3

식별자 수정 –

+1

먼저 들여 쓰기를 수정하십시오. 둘째, 두 번째 버전에서 그 부분이 어디에서 나올 것으로 예상됩니까? –

+1

우선 들여 쓰기를 수정해야합니다. –

답변

0

두 번째 예에서는 myCourse을 선언하지 않습니다.

myCourse = Course.Course(name,number,units,instructor) 

이 누락되었습니다.

0

파이썬에는 모든 함수마다 고유 한 네임 스페이스가 있습니다. 함수에서 변수를 만들면 함수가 반환 될 때까지 변수가 활성화되고 함수 내부에서만 변수에 액세스 할 수 있습니다.

문제를 해결하려면 첫 번째 함수를 호출하고 반환 값을 가져야합니다. 다음 값으로 두 번째 함수를 호출합니다.

def add_Course(): 

    name = input("Enter course name: ") 
    number = input("Enter course number: ") 
    units = input("Enter courses units: ") 
    instructor = input("Enter courses Instructor: ") 
    myCourse = Course.Course(name,number,units,instructor) 

    print("Courses' Name: ",myCourse.getName()) 
    print("Courses' Number: ",myCourse.getNumber()) 
    print("Courses' Units: ",myCourse.getUnits()) 
    print("Courses' Instructor: ",myCourse.getInstructor()) 
    print("Course Added!") 
    return myCourse 

def view_Course(myCourse): 

    print("Courses' Name: ",myCourse.getName()) 
    print("Courses' Number: ",myCourse.getNumber()) 
    print("Courses' Units: ",myCourse.getUnits()) 
    print("Courses' Instructor: ",myCourse.getInstructor()) 

course = add_Course() 
view_Course(course) 
+0

나머지 코드를 추가했습니다. 내가 조언을하면 사용자에게 코스 정보를 묻습니다. 사용자가 해당 옵션을 선택했을 때만 표시하고 싶습니다. – Supreme

+0

글쎄, 그건 다른 문제이고 다른 질문이어야합니다. –

+0

미안해 내가 새로운 질문을하게 만들지. – Supreme