📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 338question

PRACTICAL PROGRAMS WITH SOLUTION

Chapter 4: 6 · COMPUTER SCIENCE

PRACTICAL PROGRAMS WITH SOLUTION Practical Guide 12th Computer - - INDEX S No Question Number Program Name Page Number PY1 (a) Calculate Factorial (b) Sum of Series PY2 (a) Odd or Even (b) Reverse the String PY3 Generate values and remove odd numbers PY4 Generate prime numbers and set operations PY5 Display a string elements - using class DB6 MySQL - Employee table DB7 MySQL - Student table PY8 Python with CSV PY9 Python with SQL PY10 Python Graphics with PIP 12th Computer - - PY1( a ) – Calculate Factorial ( a ) Write a program to calculate the factorial of the given number using for loop (Don’t use built-in function factorial). Aim: To calculate the factorial of the given number using for loop. Coding: num = int(input('Enter a Number: ')) fact = for i in range( ,num+ ): fact = fact * i print("Factorial of ", num, " is ", fact) Output : Enter a Number: Factorial of is Result: Thus the Python program to calculate factorial has been done and the output is verified. PY1 (b) - Sum of Series ( b ) Write a program to sum the series / + / + / + …….

n n /n Aim To calculate the sum of the series : / + / + / + ……. n n /n Coding: n = int(input("Enter a value of n: ")) s = for i in range( ,n+ ): a= (i**i)/i s=s+a print("The sum of the series is ", s) Output : Enter a value of n: The sum of the series is 12th Computer - - PY2( a ) – Odd or Even ( a ) Write a program using functions to check whether a number is even or odd. Aim: To check whether a number is even or odd using user defined function . Coding: def oddeven(a): if (a% == ): return "Even" else: return "Odd" num = int(input("Enter a number: ")) print("The given number is ", oddeven(num)) Output : Enter a number: The given number is Odd Enter a number: The given number is Even Result: Thus the Python program to check whether a number is odd or even has been done and the output is verified.

PY2( b ) – Reverse the string ( b ) Write a program to create reverse of the given string. For example, “wel” = “lew“. (Don’t use string slice with stride operation) Aim: To create a reverse of the given string Coding: def reverse (str1): str2='' for i in str1: str2 = i + str2 return str2 word = input("\n Enter a String: ") print("\n The reverse of the given string is: ", reverse(word)) 12th Computer - - Output : Enter a String: school The reverse of the given string is: loohcs Result: Thus the Python program to reverse the string has been done and the output is verified. PY3 – Generate values and remove odd numbers

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →