Page 237 - Computer Science Class 11 Without Functions
P. 237
print(' ', end='')
for j in range(2*(n-i-1)-1):
print('*', end='')
print()
3. You must have studied HCF(Highest Common Factor) and LCM ( Least Common Multiple) in mathematics. Your mathematics
teacher wants you to write a program in Python to accept two numbers and then calculate and display LCM and HCF for
those two numbers.
Ans: '''
Objective: To compute LCM and HCF
Input: num1, num2 - numeric value
Output: LCM and HCF
'''
num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))
if num1 > num2:
small = num2
else:
small = num1
for x in range(1,small+1):
if (num1 % x == 0) and (num2 % x == 0):
HCF = x
LCM =(num1*num2)/HCF
print('The LCM of ', num1, ' and ', num2, ' is ', int(LCM))
print('The HCF of ', num1, ' and ', num2, ' is ', HCF)
Assessment
A. Multiple Choice Questions
1. Which of the following will return a sequence of numbers within a specified range?
a. range() b. Range() c. Sequence() d. sequence()
2. Which of the following options is the correct sequence that will be returned by the function range(-4, 8, 4)?
a. [-4, 0, 4] b. [4, 0, -4] c. [-4, 0, 4, 8] d. [8, 4, 0, -4]
3. Which of the following options represents the correct sequence that will be returned by the function range(20, 15)?
a. [20, 19, 18, 17, 16, 15] b. [20, 19, 18, 17, 16] c. [] d. [15, 16, 17, 18, 19]
4. What will be the output produced on the execution of the following code?
city = ‘Chennai’
for c in city:
print(c.upper(), end=’#’)
a. CHENNAI# b. C#h#e#n#n#a#i# c. C#H#E#N#N#A#I# d. Chenai#
5. Which of the following statements is equivalent to range(5)?
a. range(0, 5) b. range(1, 5) c. range(0, 5, 0) d. range(1, 5, 1)
6. How many numbers will the following loop print ?
for i in range(-3):
print(i)
a. 2 b. 3 c. 0 d. Will result in an error
Looping in Python 235

