anonymous
  • anonymous
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
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
katieb
  • katieb
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
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!

Looking for something else?

Not the answer you are looking for? Search for more explanations.