Skip to main content

Posts

Showing posts from 2019
DBS Preboard Class X Python Answer Keys    Q-6)        (i) print(2==2)                   Ans: True       (ii) print(4!=10)                 Ans: True       (iii) print(25/3)                  Ans: 8.333333333333334       (iv) print([2,3,4]*2)           Ans: [2,3,4,2,3,4]   Q-7)       (i) List=[1,2,3,4,5,6,7]           print(List[2:4])               Ans: [3,4]           print(List[0::2])             Ans: [1,3,5,7]           print(List[::-1])      ...
Prime Number: A prime number is a natural number greater than 1 that has no positive divisors other  than 1 and itself. Example 2,3,5,7,11,13,17 Program-1 # Python code to check a given number is prime or not num = 15 if num > 1 :     for i in range ( 2 , num / / 2 ):         if (num % i) = = 0 :             print (num, "is not a prime number" )             break     else :         print (num, "is a prime number" )     else :     print (num, "is not a prime number" )    Program-2   # Python code to print all the prime numbers within an interval   low = 6   high = 51   print ( "Prime numbers between" , low , "&" , high , "are:" )    ...
Factorial: The factorial of a number is the product of all the integers from 1 to that number. Program-1   num=5   fact = 1   if num < 0:       print("Sorry, factorial does not exist for negative numbers")   elif num == 0:       print("The factorial of 0 is 1")   else:       for i in range(1,num + 1):           fact = fact*i       print("The factorial of",num,"is",fact) Program-2 num=int(input("Enter any number:")) fact=1 while num:    fact=fact*num    num=num-1 print("factorial is ",fact) Program-3 # Factorial of a number using recursion   def fact(n):    if n == 0 or n==1:           return 1     else:        ...