Question 45: Write a Python program that will calculate area and circumference of circle using inbuilt Math Module. Download hole Program / Project code, by clicking following link: What is the output of the following program? import random
print random.randint(0, 5)
print random.random()
print random.random() * 100
List = [1, 4, True, 800, "Python", 27, "hello"]
print random.choice(List)
It appears that you're using Python 2 syntax. In Python 2, you don't need parentheses when calling functions. In Python 3, you should use parentheses when calling functions. Here's the corrected Python 2 code:
import random
print random.randint(0, 5)
print random.random()
print random.random() * 100
my_list = [1, 4, True, 800, "Python", 27, "hello"]
print random.choice(my_list)
The corrected Python 2 code would produce the following output:
# This output will vary as it depends on random values generated.
# Example outputs:
2
0.983234729731
69.2704343627
4
In this code, you're using the random module to generate random numbers.
Here's a summary of what each line does: - random.randint(0, 5): Generates a random integer between 0 and 5 (inclusive).
- random.random(): Generates a random floating-point number between 0 and 1.
- random.random() * 100: Generates a random floating-point number between 0 and 100.
- random.choice(my_list): Selects a random item from the given list my_list. The actual output here will depend on which item is randomly chosen from the list.
Programming Code: Following code write in: BP_P45.py # Python Program
# calculate Area and Circumference of Circle
# Using inbuilt Math Module
# import math lib.
import math
def circle_Circumference(radius):
return 2 * math.pi * radius
def circle_Area(radius):
return math.pi * radius * radius
radius = float(input("Enter Radius of Circle: "))
print("Given Radius of Circle is: ", radius)
print("Circumference of Circle is: ", circle_Circumference(radius))
print("Arear of Circle is: ", circle_Area(radius))
# Thanks for Reading.
Output:
print random.randint(0, 5)
print random.random()
print random.random() * 100
List = [1, 4, True, 800, "Python", 27, "hello"]
print random.choice(List)
It appears that you're using Python 2 syntax. In Python 2, you don't need parentheses when calling functions. In Python 3, you should use parentheses when calling functions.
import random
print random.randint(0, 5)
print random.random()
print random.random() * 100
my_list = [1, 4, True, 800, "Python", 27, "hello"]
print random.choice(my_list)
The corrected Python 2 code would produce the following output:
# This output will vary as it depends on random values generated.
# Example outputs:
2
0.983234729731
69.2704343627
4
Here's a summary of what each line does:
- random.randint(0, 5): Generates a random integer between 0 and 5 (inclusive).
- random.random(): Generates a random floating-point number between 0 and 1.
- random.random() * 100: Generates a random floating-point number between 0 and 100.
- random.choice(my_list): Selects a random item from the given list my_list. The actual output here will depend on which item is randomly chosen from the list.
# Python Program # calculate Area and Circumference of Circle # Using inbuilt Math Module # import math lib. import math def circle_Circumference(radius): return 2 * math.pi * radius def circle_Area(radius): return math.pi * radius * radius radius = float(input("Enter Radius of Circle: ")) print("Given Radius of Circle is: ", radius) print("Circumference of Circle is: ", circle_Circumference(radius)) print("Arear of Circle is: ", circle_Area(radius)) # Thanks for Reading.
Output:
0 Comments