CHAPTER 4 AI WITH PYTHON 1
Q. 1. Choose and tick () the correct answer from the given options.
a. JavaScript
b. Matplotlib
c. All of these
d. int()
e. %
Q. 2. State whether the following sentences are true or false:
a. True
b. False
c. False
d. True
e. False
Q. 3. Answer the following questions:
a. A variable is a named location used to store data in the memory.
Python has no command for declaring a variable. The equal sign
(=) is used to assign values to variables.
b. Valid variable names: Address1, RollNumber, ContactDetails,
First_name.
Invalid variable names: @Email, 1Day, age# .
c. To have a multi-line comment, use triple quotes (either ’’’ or ”””)
at the beginning and the end of the comment. Syntax: ’’’ Here
we are writing a basic program. Using the print statement This is
a multiple line comment. ’’’
d. 15 / 2: This expression uses the ‘/’ operator, which performs
normal division.
15 // 2: This expression uses the ‘//’ operator, which performs
floor division. Floor division divides two numbers and rounds the
result down to the nearest integer. ‘
Q. 4. Answer the following questions in brief.
a. The print is a predefined function, which is used to display
information on the screen.The information to be displayed is
enclosed within the parenthesis. Each print statement displays
the output on a new line.
Syntax: print(“Message”)
b. Table on page no.
c. The ‘elif’ statement enables us to check multiple conditions and
execute the specific block of statements depending upon the true
condition amongst them.
Syntax:
if condition 1:
# block of statements
elifcondition 2:
# block of statements
else:
# block of statements
Q. 5. Do as directed.
a. Total_runs= int(input("Enter the total runs scored:"))
Total_matches_played=int(input("Enter the total matches
played:"))
Number_of_notout=int(input("Enter the number of not out:"))
Batting_average=(Total_runs/(Total_matches_played-Number_of
_notout))
print("Batting_average=",Batting_average)
b. hr= int(input("Enter the time in 12 hr format"))
if hr!=12:
hr=hr+12
elif hr == 12:
hr = 0
print("Time in 24 hour:",hr)
c. meters = float(input("Enter distance in meters: "))
kilometers = meters / 1000
print("The distance in meters :", kilometers,"km")
d. a= int(input("Enter the first number"))
b= int(input("Enter the second number"))
sum=a+b
product=a*b
print("The sum of two integers:",sum)
print("The product of two integers:",product)
e. Number_of_km= float(input("Enter the number of kilometers"))
Quantity_of_fuel_consumed= float(input("enter the quantity of
fuel consumed"))
Car_mileage= (Number_of_km/Quantity_of_fuel_consumed)
print("Car_mileage:",Car_mileage)
f. a= int(input("Enter the number") )
if a%2==0:
print("the number is even")
else:
print("the number is odd")
g. n= int(input("Enter the number"))
if n % 2 == 0 and n % 5 == 0:
print("the number is divisible by both 2 and 5")
else:
print("the number is not divisible by both 2 and 5")
h. num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
if num1==num2:
print("both numbers are equal")
elif num1<num2:
print("number2 is greater than number1")
else:
print("number1 is greater than number2")
i. vowels = "AEIOUaeiou"
character = input("Enter a single character: ")
if character in vowels:
print("The character is a vowel")
else:
print("The character is not a vowel")