Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:39:08+00:00 2026-06-16T22:39:08+00:00

Firstly, I am new to Python so please go easy on me… Secondly, I’ve

  • 0

Firstly, I am new to Python so please go easy on me… Secondly, I’ve never used a forum before so if I paste too much code or don’t give exactly what you need, forgive me, I shall try my best:

WHAT I NEED MY CODE TO DO:

I need my code to ask the user for an input called moduleName then after moduleName is entered I need it to ask the user for the grade for that specific module. After that is entered I need it to ask again for module then the grade until there are no more to enter where by the user will enter -1 into the module bit to end it. I also need each item to save to a global list I have created. So when I use teh function I have created to view the list it prints out all modules and grades.

MY CODE THUS FAR: (my global list is at top of code named students[])

def addStudent():
    print 
    print "Adding student..."
    student = Student()
    firstName = raw_input("Please enter the student's first name: ")
    lastName = raw_input("Please enter the student's last name: ")
    degree = raw_input("Please enter the name of the degree the student is studying: ")
    studentid = raw_input("Please enter the students ID number: ")
    age = raw_input("Please enter the students Age: ")
    **moduleName= 0
    while moduleName != "-1":
        moduleName = raw_input("Please enter module name: ")
        grade = raw_input ("Please enter students grade for " + moduleName+": ")
    students.append(student)**


    student.setFirstName(firstName) # Set this student's first name
    student.setLastName(lastName)
    student.setDegree(degree)# Set this student's last name
    student.setGrade(grade)
    student.setModuleName(moduleName)
    student.setStudentID(studentid)
    student.setAge(age)


    print "The student",firstName+' '+lastName,"ID number",studentid,"has been added to the system."

THE OUTPUT I GET:

I have now fixed the loop so it breaks correctly… the only problem I have now is that the moduleName and grade fields save to my global list but only save the last input (being -1) as opposed to the multiple inputs entered… so confused.
The problem may also lie within this function I have created:

def viewStudent():
    print "Printing all students in database : "

    for person in students:
            print "Printing details for: " + person.getFirstName()+" "+ person.getLastName()
            print "Age: " + person.getAge()
            print "Student ID: " + person.getStudentID()
            print "Degree: " + person.getDegree()
            print "Module: " + person.getModuleName()
            print "Grades: " + person.getGrade()

Again apologies I don’t know what’s needed on forums etc so go easy on me…
Thank in Advance! =D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:39:10+00:00Added an answer on June 16, 2026 at 10:39 pm

    I would suggest replacing the while moduleName != "-1": loop with a while True: loop, and then insert this code after asking for the module name:

    if moduleName == '-1':
        break
    

    This will break out of the while loop when you want it to.

    Addressing your second question, the append function is in the else bit of the whole while loop. This means that it only works when the function breaks. You need to put this in the main while loop after you get the input, and get rid of the else.

    Also, I don’t see student defined anywhere – what is it meant to be?

    Here’s the code you want:

    while True:
        moduleName = raw_input("Please enter module name: ")
        if moduleName == '-1':
            break
        grade = raw_input("Please enter students grade for " + moduleName+": ")
        students.append(student)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new so firstly please excuse me if I am doing anything
Firstly, Happy New Year everyone. I'm new to Rails, so please tolerate any incorrect
Firstly ... I'm new in python and suds.. Now I wanna dynamically call a
Firstly, I'm new to SSRS so please forgive me if this is really baby
Firstly, I'm new to Python, Qt and PySide so forgive me if this question
Firstly I'm new to Redis so please bear with me, as I'm sure this
Firstly I am new to android and Java so this is a beginners question.
see fiddle Firstly i am new to jquery. i have to make one cell
Firstly, I am very new to function pointers and their horrible syntax so play
Firstly, I am somewhat new with Hibernate. To get to know the technology I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.