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 Python Basics Functions and Looping Functions

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

How to create a function for the following

In the question section this question was given. How would i convert this into a function Could someone please provide an answer to this Thanks in advance

first_number = 5 first_result = first_number * first_number print("The number {} squared is {}".format(first_number, first_result))

second_number = 8 second_result = second_number * second_number print("The number {} squared is {}".format(second_number, second_result))

2 Answers

berend folkers
berend folkers
950 Points

def squared(number): number_squared = number * number result = "The number {} is squared {}".format(number, number_squared) print(result)

squared(5) squared(8)

berend folkers
berend folkers
950 Points

you may have to restyle in de editer again. (I dont know how to copy past it proparly)