Robotics & Artificial Intelligence
Write a user-defined function def Circle() to input radius of a circle from the user. The program calculates area and circumference inside the function. Finally, it returns the values to main program to display the result.
Python Functions
1 Like
Answer
def Circle(r):
ar = 3.14 * r * r
cir = 2 * 3.14 * r
return(ar, cir)
radius = float(input("Enter radius of circle:"))
area, circumference = Circle(radius)
print("Area of circle:", area)
print("Circumference of circle:", circumference)Output
Enter radius of circle:7
Area of circle: 153.86
Circumference of circle: 43.96
Answered By
2 Likes
Related Questions
Assertion (A): When the user defines a function of his/her own and use it in the program to perform a specific task, it is known as user defined function.
Reason (R): The types of functions viz. built-in functions and modules are also known as user defined functions because they are not defined by the system developers. Thus, it is not necessary that the system developers are only authorised for creating a function.
Based on the above discussion, choose an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.
The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The following program is designed to generate next five terms of the Fibonacci series, excluding 0 and 1 (i.e., first two terms of the series). The incomplete user-defined program is given as under:
def Fibo_Series(): a = 0 b = 1 count = ........... # Line 1 while(count <= ............): # Line 2 c = a + b print(.............) # Line 3 a = ............. # Line 4 b = c count = count + 1 # main program Fibo_Series()Now, complete the above program to generate next five numbers of the series as 1, 2, 3, 5, 8.
Write a user-defined function
def Perfect()to input a number from the user. The program checks whether it is a perfect number or not. Finally, it returns the values to main program to display the result.A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself.
For example, 6 = 1 + 2 + 3
It is a perfect number.
Write a user-defined function
def Sum_Digits()to input a number from the user. The program calculates sum of the digits of the number inside the function without returning any data to the main program.Sample Input: 345
Output: 3 + 4 + 5 = 12