Default Folder
Default Folder
FILTERTEMPLE
print(i)
1947 .
SZER SAREE
EXERCENT
12. Write a program to input a number from the user and display its table using for loop ( e.g. 2* =2
1 ) .
num - int( input ("Please enter a number ")
: )
if num >0 :
for x in range ( 1,11,1 ) .
print num
( ,X
" " x
, "-
, " num
, *x )
else :
print (" Entered number should be greater than zero ")
13. W r i t e a program to input a number from the user and
display its factorial .
For 0 it displays the message "The factorial of 0 is "
1 .
For negative numbers displays "Factorials of negative
it
numbers doesn't exists " .
num = int(input("Please enter a number :") )
factorial= 1
num < 0 ) :
if(
print(" Factorials of negative
numbers doesn't exists ")
elif( num == 0 ):
print("The factorial of 0 is 1 ")
else :
for i in range (2 num +
, 1) :
factorial factorial * i
print("The factorial of " num, ," is " factorial )
,
Write a program to input a number from the user to check whether th amber is prime or not
using while loop .
num1 = int (input ("Enter any number : ") )
k=0
ifnum1 0 or num1 == 1
=
: :
print( "Not a prime number ")
else :
i= 2
while( i<num 1) :
ifnum1 % i== 0 :
k = k+ 1
=
i +
i l
ifk == 0 :
print ( num1 , " is prime number ")
else :
print num1
( , "is not prime number " )
Write a program to create a list of 5 names and display it with its index value .
15. Write a program
to create a list of 5 names and display it with its index value .
list1= [ Sam
" " John "
" "Sophia "
Mae
,
," "Jack " ]
,
" ,
print (list1 [0 ] )
print (list! [ 1] )
print (list 2
][ ])
print( list1[3 ])
print( list1 [4 ] )
16. Write a program to create a list with the following numbers and perform
the given tasks:
a.
b.
c .
10,23456789
list.
list.
.
list
d . Remove 18 from the list and display the final list with all the elements in it.
list1= { 10,11,12,13,14,15,16,17,18,19,20 ]
list1 append (21 )
print( list !)
list1 pop (3 )
print ( list )
print ( list1[4 ] )
list1 remove( 18 )
print (list )
17. W r i t e a program to create a list of 3 numbers and perform the following given tasks :
a. Insert any two numbers at the beginning of the list.
b . Remove the item (number ) at 3rd position .
c. Display the sum of first two items of a list.
d . Display the reverse of list.
list1 (10,11,12 ]
list1.insert(0,6 )
list1.insert( 1,7)
print( list1 )
list1.pop(4 )
print ( list1 )
print (list1 [0 ]+ list1[ 1])
list1.reverse()
print ( list1 )
Page 4 / 4