Write a new function definition that takes a character (i.e. Write a simple program to test the function. You should NOT use the built-in Python len() function for this task. Define a new function string_length() that takes a string as a parameter and returns the length of the string. Define a new function max_of_three () that takes three numbers as parameters and returns the largest. (It is true that Python has a max () function built in, but writing one yourself is good practise). You should use an if else statement inside the function definition. Define a new function max2 () that takes two numbers as parameters and returns the largest. Write a program to output the first 10 square numbers - you should use the function defined in task 1 to perform the square operation on the numbers. Then write a simple program to test the function this should prompt the user to enter a number to be squared, a function call passing this number as an argument, and finally the value returned by the function should then be printed back to the user. Write a Python function definition that takes one integer (whole number) as a parameter, calculates the square of that number, and returns the result. Exercise 2-User-Defined Functions Exercises 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |