Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kah712 Group Title

MOOC Handout 2 sec(2.8) function report_card takes users grades, then program prints out report card w/ GPA. Here is my code so far: def report_card(): classes = int(raw_input("How many classes did you take?")) class_name = raw_input("What was the class name?") grade = raw_input("what was your grade?") data = class_name + " - " + grade my_list = [] my_list.append(data) print my_list report_card() How do I get multiple sets of input? I want the # in "classes" to be the # of times my program asks for raw_input to create a list of grade + class_name

  • 10 months ago
  • 10 months ago

  • This Question is Closed
  1. Denu8 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Well, You would need a loop. Using a loop, a for loop in this case is easy, we can ask a certain amount of time. The one main difference is we are gonna have to move the initialization for your list. def report_card(): my_list = [] classes = int(raw_input("How many classes did you take?")) for i in range(0, classes): class_name = raw_input("What was the class name?") grade = raw_input("what was your grade?") data = class_name + " - " + grade my_list.append(data) print my_list This will run you through the loop the amount of times that is specified. Understand that a for loop has the syntax of for (variable) in (separable data). The variable contains a piece of the data inputted, so if you put a string in there each time you go through it would be a different character, so for instance if you put 'Grandma' in there, the first time through the variable would be 'G', the second time 'r', and so on. With the range function, we can think of it as returning a tuple (0 , ..., classes -1), and the for loop splits each part of the tuple off, so it starts with zero and ends at classes -1. We don't use the variable in this instance, but a for loop is still useful because it only runs a specified amount of times with out having to create a new variable and increment it at the end of the loop. So there's the code and the explanation. Good luck!

    • 10 months ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.