What is the output of the following code?``` def add(x, y):
return x + y
Print (add(20,30))
30
Question: What does BMI stand for?
Body mass index
Question: How can you generate a random number between 1 and 100 in Python?
random.randint(1,100)
Question: How can you import the math module in Python?
Answer: By using the import keyword. For example, import math.
Question: What is the result of `3 ** 2` in Python?
Answer: 9 (The `**` operator performs exponentiation)
Question: What is the result of the expression 2 + 3 * 4?
14
Question: How do you calculate BMI?
Answer: BMI is calculated by dividing a person's weight in kilograms by the square of their height in meters.
Question: Write a Python program that allows a player to guess a randomly generated number between 1 and 10.
import random
number = random.randint(1, 10)
guess = int(input("Guess the number between 1 and 10: "))
if guess == number:
print("Congratulations! You guessed correctly.")
else:
print("Sorry, wrong guess. The number was", number)
Question: What are some functions available in the math module?
Answer: Examples of functions in the math module include sqrt(), sin(), cos(), exp(), log(), and more.
2. Question: How can you check if a number is even in Python?
Answer: By using the modulo operator `%`. If the result of `number % 2` is 0, then the number is even.
Question: How can you calculate the square root of a number in Python?
math.sqrt()
Question: Write a Python function that calculates BMI given weight in kilograms and height in meters.
def calculate_bmi(weight, height):
bmi = weight / (height ** 2)
return bmi
weight = float(input("Enter weight in kilograms: "))
height = float(input("Enter height in meters: "))
bmi = calculate_bmi(weight, height)
print("Your BMI is", bmi)
Question: What is the purpose of the input() function in Python?
To get the user input from the keyboard
Question: How can you use the random module to generate a random number between 1 and 10?
Answer: By using the random.randint() function. For example, random.randint(1, 10).
3. Question: How can you concatenate two strings in Python?
Answer: By using the `+` operator. For example, `"Hello, " + "World!"` will result in the string "Hello, World!".
Question: How can you convert a string containing a number to an integer in Python?
Answer: By using the int() function. For example, int("42") will convert the string "42" to the integer 42.
Question: Is a BMI of 25 considered overweight or underweight?
Overweight
Question: How can you check if a guessed number is higher or lower than the target number in a number guessing game?
Answer: By using conditional statements such as if and else. For example, if guess > target: print("Too high").
Question: What is the purpose of the datetime module in Python?
Answer: The datetime module provides classes for working with dates, times, and intervals.
Question: How can you create a list containing the numbers 1, 2, and 3 in Python?
Answer: By using square brackets and separating the elements with commas. For example, `[1, 2, 3]`.
What is a def function
I will decide the definition
Question: What are the BMI categories according to the World Health Organization (WHO)?
Answer: Underweight: BMI < 18.5, Normal weight: 18.5 <= BMI < 25, Overweight: 25 <= BMI < 30, Obesity: BMI >= 30
Question: How can you convert a string input to an integer in Python?
Answer: By using the int() function. For example, int(input("Enter a number: ")).
What is a while loop and for loop
I will decide the answer
Question: What is the purpose of the `len()` function in Python?
Answer: The `len()` function is used to determine the length or size of a sequence (e.g., a string, list, or tuple).