0

This code I have gives the information of someone's name, gender, age, department, email, now I have to change it so the user can input their information instead of the info already there and I dont know how.

Anything will be usefull if you've seen a similar code that can help please comment thanks.

class Student:
    #name, gender, age, department, email, tuition
    def __init__(self, name, gender, age, department):
        self.name = name
        self.gender = gender
        self.age = age
        self.department = department
        self.email = f"{self.generate_account(name)}@example.com"

    def generate_account(self, name):
        fname = name.lower()[:name.index(" ")]
        lname = name.lower()[name.index(" ")+1:]
        return lname + fname

    def set_department(self, new_department):
        self.department = new_department

    def __str__(self):
        str = f"name = {self.name}\n"
        str = str + f"gender = {self.gender}\n"
        str = str + f"age = {self.age}\n"
        str = str + f"department = {self.department}\n"
        str = str + f"email = {self.email}\n"
        return str

student1 = Student("John Who", "Male", 19, "Social Science")
print(student1)

Result:

Name = John Who
Gender = Male
Age = 19
Department = Social Science
Email = [email protected]

1 Answer 1

2

Welcome to Stack!

Use the input() function! You can read more about it here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.