Skip to content

Instantly share code, notes, and snippets.

@Committing
Last active March 8, 2022 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Committing/ccda3180ab22de49374b to your computer and use it in GitHub Desktop.
Save Committing/ccda3180ab22de49374b to your computer and use it in GitHub Desktop.
Richard homework - You're welcome ;)
def addPerson(user_number):
print "Enter person #" + str(x)
name = raw_input('Enter name: ')
if name.isalpha() :
print "Name accepted"
else :
print "Please enter a valid name."
return False
age = raw_input('Enter age: ')
if age.isdigit() and int(age) > 0 and int(age) < 130 :
print "Age accepted"
else :
print "Please enter a valid age."
return False
names.append(name)
ages.append(age)
return True
how_many_users = raw_input('How many users do you want to add? ')
names = []
ages = []
if int(how_many_users) > 0 :
for x in range(1, int(how_many_users) + 1) :
while True :
if addPerson(x):
print "User added"
break;
else :
print "Please try again."
print names.sort()
print ages.sort(reverse=True)
print "========================================"
print "RESULTS"
print "========================================"
print "Names in ascending order: "
for key, name in enumerate(names) :
print str(key + 1) + ". " + name
print "========================================"
print "Ages in decending order: "
for key, age in enumerate(ages) :
print str(key + 1) + ". " + age
print "========================================"
print "Merged list data: "
for key, age in enumerate(ages) :
nameConverted = names[key] if len(names) > key else ''
print str(key + 1) + ". Name: " + nameConverted + ' Age:' + age
else :
print 'Cheers anyway.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment