Python Challenge
Python Challenge
"""
In this program would be asking the user how many times they would like to
enter a name and age and not accept floats, strings, and negative integers.
After asking the user for the name and age(, the program will store it in two
different
lists and then sort it and display both of them. After that it will change the
second name to "Gomez" and add "George" to the list containing the names. After
that
It will take the seocnd age in the list containing the ages and divide it by the
first one and round it to the third decimal place. Then the program will create
a new list and combining the the list containing the ages to the list containing
the names. Then it will take the lowest value in the list containing the ages and
multiply it by two and then sorting the list containing the names and sort the
list containing the ages and then combine the list containing the names to the
list containing the ages.
"""
#Asks the user for the names and ages to store in the blank lists and will not
allow them to enter a float, string, or negative number.
for i in range(times):
input_names = input("Please enter a name: ")
input_ages = input("Please enter " + input_names + "'s age: ")
try:
ages = int(input_ages)
if ages > 0:
age.append(ages)
name.append(input_names)
print("")
else:
print("Must enter positive integer for the age.")
print("")
except ValueError:
print("Must enter positive integer for the age.")
print("")
#Sort and display both lists.
name.sort()
age.sort()
print("Sorted names:")
print(name)
print("Sorted ages:")
print(age)
#Divide the second age in the list by the first age and round to 3 decimal places
and display the result
print("The second age in the list divided by the first one, rounded to 3 decimal
places:")
divison = age[1]/age[0]
divison = round(divison, 3)
print(divison)
#Create a new list by combining the Names and Ages lists and display
print("")
print ("Merged list of names and ages: ")
merged = name + age
print(merged)
#Replace the lowest number in the list with that number doubled and display the
newly sorted list
print("")
print("Replace lowest age with 2x that number and display the newly sorted list: ")
new = age[0] * 2
age[0] = new
age.sort()
name.sort()
other = age+name
print(other)