Xii CS Python Programs 2023 2024 - 240226 - 192836
Xii CS Python Programs 2023 2024 - 240226 - 192836
str="COMPUTER" COMPUTER
COMPUTE
index=len(str) COMPUT
30. Display format for i in str: COMPU
COMP
print(str[0:index]) COM
index-=1 CO
C
print(i, end=' ') 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243
245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279
281 283 285 287 289 291 293 295 297 299 301 303 305 307 309 311 313 315
317 319 321 323 325 327 329 331 333 335 337 339 341 343 345 347 349 351
353 355 357 359 361 363 365 367 369 371 373 375 377 379 381 383 385 387
389 391 393 395 397 399 401 403 405 407 409 411 413 415 417 419 421 423
425 427 429 431 433 435 437 439 441 443 445 447 449 451 453 455 457 459
461 463 465 467 469 471 473 475 477 479 481 483 485 487 489 491 493 495
32. display 3 digit 497 499 501 503 505 507 509 511 513 515 517 519 521 523 525 527 529 531
533 535 537 539 541 543 545 547 549 551 553 555 557 559 561 563 565 567
odd numbers 569 571 573 575 577 579 581 583 585 587 589 591 593 595 597 599 601 603
605 607 609 611 613 615 617 619 621 623 625 627 629 631 633 635 637 639
641 643 645 647 649 651 653 655 657 659 661 663 665 667 669 671 673 675
677 679 681 683 685 687 689 691 693 695 697 699 701 703 705 707 709 711
713 715 717 719 721 723 725 727 729 731 733 735 737 739 741 743 745 747
749 751 753 755 757 759 761 763 765 767 769 771 773 775 777 779 781 783
785 787 789 791 793 795 797 799 801 803 805 807 809 811 813 815 817 819
821 823 825 827 829 831 833 835 837 839 841 843 845 847 849 851 853 855
857 859 861 863 865 867 869 871 873 875 877 879 881 883 885 887 889 891
893 895 897 899 901 903 905 907 909 911 913 915 917 919 921 923 925 927
929 931 933 935 937 939 941 943 945 947 949 951 953 955 957 959 961 963
965 967 969 971 973 975 977 979 981 983 985 987 989 991 993 995 997 999
Enter the number:5
n=int(input("Enter the number:")) 5X1=5
5 X 2 = 10
33. n-Multiplication for i in range(1,11): 5 X 3 = 15
5 X 4 = 20
Table print(n,'x',i,"=",n*i) 5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50
i=4
while(i<=8): 1 2 3 4
34.Ddisplay format for j in range (1,i+1): 1 2 3 4 5
print(j,end=' ') 1 2 3 4 5 6
1 2 3 4 5 6 7
print(end='\n') 1 2 3 4 5 6 7 8
i+=1
defcompute_lcm(x, y):
if x > y: Enter the number1 :54
greater = x Enter the number2 :24
else: The L.C.M. is 216
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
35.find LCM 2 numbers lcm = greater
break
greater += 1
return lcm
num1 = int(input("Enter the number1 :"))
num2 = int(input("Enter the number2 :"))
print("The L.C.M. is", compute_lcm(num1,
num2))
def factorial(x):
if x == 1: Enter the n number: 5
return 1 The factorial of 5 is 120
36. Recursive function
else:
N factorial
return (x * factorial(x-1))
num = int(input("Enter the n number: "))
print("The factorial of", num, "is", factorial(num))
str1="Welcome" WelcomeWelcomeWelcomeWelcome
37. Repeating(*)
print(str1*4)
str1="Welcome to Python" Welcome to Python
print(str1) Python
print(str1[11:17]) Pto
38. string
eg Wotyn
print(str1[11:17:2])
Mar-2020 nytoW
print(str1[::4])
print(str1[::-4])
str1="THIRUKKURAL"
print(str1)
print(str1[0]) THIRUKKURAL
print(str1[0:5]) T
THIRU
print(str1[:5]) THIRU
39. string eg print(str1[6:]) KURAL
print(str1[6:10:2]) KR
print(str1[::4]) TUR
print(str1[::-4]) LKI
print(str1[-4]) U
print(str1[-4:]) URAL
N=[]
for x in range(1,11): (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
N.append(x) [2, 4, 6, 8, 10]
Num=tuple(N)
print(Num)
66. Output
for index, i in enumerate(N):
if(i%2==1):
del N[index]
print(N)
class sample:
num=0 The object value is= 15
def __init__(self,var): The value of class variable is= 1
sample.num+=1 The object value is= 35
self.var=var
The value of class variable is= 2
print("The object value is=",self.var)
print("The value of class variable The object value is= 45
73.Output (del) is=",sample.num) The value of class variable is= 3
def __del__(self): Object with value 15 is exit from the scope
Object with value 35 is exit from the scope
sample.num-=1
Object with value 45 is exit from the scope
print("Object with value %d is exit from
the scope"%self.var)
s1=sample(15)
s2=sample(35)
s3=sample(45)
del s1,s2,s3
class sample:
__num=10 10
def disp(self): 10
75.Output print(self.__num) None
s=sample()
s.disp()
print(s.disp())