Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Help with shortening this code

I am under the impression there is a way to shorten this is what I am looking for, any suggestion would be greatly appreciated. I could take out def ypc(ave): and rushing_av and ave and just do print(yds / att) but I am try get used to functions. Also wondering why def ypc(yds, att): does not work? That is what I first tried. (each number is the corresponding line of the code).

(1) def ypc(ave): (2) return yds / att (3) yds = input("Yards gained? ") (4) yds = int(yds) (5) att = input("Rushing attempts? ") (6) att = int(att) (7) ave = yds / att (8) rushing_av = ypc(ave) (9) print(rushing_av)

boi
boi
14,242 Points

First thing is to learn how to Ask a question. You've provided no context of your code, and you got -5 on the formatting side.

Provide a context of what is your code doing, and what it's not doing or should not be doing.

Learn the formatting here.

If your question is easy to understand and clear to read, it would be answered faster. Sometimes people completely omit your question due to improper methods.