Learned alot in this first week, following PCC, but biggest leaps came from the community and others giving their time to help, thank you!
All input appreciated!
Objective
Goals were to fill a class with user inputs from multiple users and then be able to call methods to each user input created class. (... did I say that right O.o)
Code
class User():
def __init__(a, first_name, last_name, city, age):
a.first_name = first_name.title()
a.last_name = last_name.title()
a.city = city.title()
a.age = age
def describe_user(a):
print("-----")
print("First Name" + " : " + a.first_name)
print("Last Name" + " : " + a.last_name)
print("City" + " : " + a.city)
print("Age" + " : " + a.age)
def ask_user(message=''):
user_input = ''
while not user_input:
user_input = input(message)
return user_input
def form_complete(values, placement, length):
placement = []
while len(placement) < length:
first_name = ask_user("Enter First Name: ")
last_name = ask_user("Enter Last Name: ")
city = ask_user("Enter City: ")
age = ask_user("Enter Age: ")
values = User(first_name, last_name, city, age)
placement.append(values)
return placement
if __name__ == '__main__':
users = form_complete('user', 'users', 3)
for a in range(len(users)):
users[a].describe_user()
Output
xenial)vash@localhost:~/pcc/9$ python3 3.py
Enter First Name: vash
Enter Last Name: the stampede
Enter City: gunsmoke
Enter Age: 131
Enter First Name: spike
Enter Last Name: spiegel
Enter City: mars
Enter Age: 27
Enter First Name: holden
Enter Last Name: caulfield
Enter City: new york city
Enter Age: 16
-----
First Name : Vash
Last Name : The Stampede
City : Gunsmoke
Age : 131
Greetings Vash!
-----
First Name : Spike
Last Name : Spiegel
City : Mars
Age : 27
Greetings Spike!
-----
First Name : Holden
Last Name : Caulfield
City : New York City
Age : 16
Greetings Holden!
(xenial)vash@localhost:~/pcc/9$