pythonprintingreadability

How can I clean up these print statements?


So, I'm playing with .csv files learning how to read and present the info. I'm printing the results to the terminal, but as I print more content, I have a wall of print statments that just keeps getting longer and longer. Is there any way to clean this up? Also, please ignore my vulgar data. I generated that csv at like 3AM.

print("")
print(people[owner]["first_name"], end = "")
print(" ", end="")
print(people[owner]["last_name"], end="")
print(" owns the most buttplugs with a total of ",end="")
print(people[owner]["plugs"], end="")
print(" buttplugs!")
print("That's ",end="")
print(people[owner]["plugs"] - round(get_avg(people)),end="")
print(" more buttplugs than the average of ",end="")
print(round(get_avg(people)),end="")
print("!")
print("")
# Result: Sonnnie Mallabar owns the most buttplugs with a total of 9999 buttplugs!
# That's 4929 more buttplugs than the average of 5070

Solution

  • avg = round(get_avg(people))
    plugs = people[owner]['plugs']
    print(
        f'\n{people[owner]["first_name"]} {people[owner]["first_name"]} '
        f'owns the most buttplugs with a total of {plugs} buttplugs!\n'
        f"That's {plugs - avg} more buttplugs than the average of {avg}!"
    )
    

    prints

    Sonnnie Sonnnie owns the most buttplugs with a total of 9999 buttplugs!
    That's 4929 more buttplugs than the average of 5070!