CBSE Class 11 Computer Science
Question 160 of 173
Data Handling — Question 12
Back to all questions 12
Question Question 12
Write a program whose three sample runs are shown below:
Sample Run 1:
Random number between 0 and 5 (A) : 2
Random number between 0 and 5 (B) :5.
A to the power B = 32
Sample Run 2:
Random number between 0 and 5 (A) : 4
Random number between 0 and 5 (B) :3.
A to the power B = 64
Sample Run 3:
Random number between 0 and 5 (A) : 1
Random number between 0 and 5 (B) :1.
A to the power B = 1
Solution
import random
a = random.randint(0, 5)
b = random.randint(0, 5)
c = a ** b
print("Random number between 0 and 5 (A) :", a)
print("Random number between 0 and 5 (B) :", b)
print("A to the power B =", c)Output
Random number between 0 and 5 (A) : 5
Random number between 0 and 5 (B) : 3
A to the power B = 125