Gec Python Assignment
Gec Python Assignment
( Roll number: )
f) Use the correct logical operator to check if at least one of two statements is True.
if 5 == 10 or 4 == 4:
print("At least one of the statements is true")
g) Evaluate: 7%(5 // 2) = 1
Q4. Write the python code that inputs two numbers from the user and returns their least
common multiple (LCM), use functions?
Ans: def lcm(a,b):
if a > b:
greater = a
else:
greater = b
while (True):
if (greater % a == 0)and( greater % b == 0):
lcm=greater
break
greater+=1
print("The LCM of the numbers is:", lcm)
def main():
x = int(input("Enter 1st number"))
y = int(input("Enter 2nd number"))
lcm(x,y)
if __name__=='__main__':
main()
Q5. a) Differentiate between the following operators with the help of an example:
1. = and ==
Ans: = is simply an assignment operator. It assign value to a variable.
Ex: a = 10 (here value 10 is assigned to variable a)
== is a relational operator. It compares the value of two operands to be
equal or not and return true or false accordingly.
Ex: a == 10 (here it check is the value of a is 10 or not)
2. / and //
Ans: / is a arithmetic operator that return the quotient of the operands in decimal form.
Ex: 10/3 = 3.333333333333….
// is a arithmetic operator, that return the quotient of the operands in integral form.
Ex: 10//3 = 3 (no decimal part is displayed)
b) Write a function to print the following pattern: (input no. of lines from the user)
1
22
333
4444
Program:
def pattern(n):
for i in range (1, n+1):
for j in range(1,i+1):
print(i, end='')
print()
def main():
num = int(input("Enter a number"))
pattern(num)
if __name__=='__main__':
main()