Reputation: 3
I am trying to create a small program that asks the user how many students are enrolled in the class and then the user enters the amount. But after that I need a loop to run for the amount of students specified by the user. Here's what I have so far.
def class ():
x = input ("How many students will be entered? ")
for count in range (x):
name = input ("What is your name? ")
major = input ("What is your major? ")
year = input ("and your year? ")
print (name, major, year)
Upvotes: 0
Views: 269
Reputation: 289
Isn't class predefined in python?
So you cant call a function "class". Also use raw_input.
Convert the input value to a string.
x = int (raw_input ("How many students will be entered? "))
Define it as a function like so:
def doSomething():
x = int (raw_input ("How many students will be entered? "))
for count in range (x):
name = raw_input ("What is your name? ")
major = raw_input ("What is your major? ")
year = raw_input ("and your year? ")
print (name, major, year)
Then just call on it:
doSomething();
Upvotes: 1
Reputation: 582
You forgot to give us your specify your problem. But its apparent that you are trying to convert str --returned by the input function-- to int type.
x = int (input ("How many students will be entered? "))
Upvotes: 0