PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] How can I clean up these print statements?

 September 15, 2022     printing, python, readability     No comments   

Issue

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!


Answered By - Michael Hodel
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,214,505

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing