CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
12th CS English Medium

Practical Program Exercise 2 odd or even – reverse the string for 12th computer science

Baskaran J
February 7, 2023 2 Mins Read
1.5K Views
0 Comments

PY 2(a) – ODD OR EVEN

QUESTION:

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%2==0):

return 1

else:

return 0

num = int(input(“Eneter a number:”))

if(oddeven(num)==1):

print(“The given number is even”)

elif(oddeven(num)==0):

print(“The given number is odd”)

 OUTPUT:

Enter a number: 7

The given number is odd

Enter a number: 6

The given number is even

RESULT:

The Output was verified successfully

Defining Functions:

  • Functions must be defined, to create and use certain functionality.
  • There are many built-in functions that comes with the language python (for instance, the print() function), but you can also define your own function.
  • When defining functions there are multiple things that need to be noted;
  • Function blocks begin with the keyword “def” followed by function name and parenthesis ().
  • Any input parameters or arguments should be placed within these parentheses when you define a function.
  • The code block always comes after a colon (:) and is indented.
  • The statement “return [expression]” exits a function, optionally passing back an expression to the caller.
  • A “return “with no arguments is the same as return None.
  • To check the given number odd or even.

PY 2(b) – REVERSE THE STRING

QUESTION:

          Write a program to create reverse of the given string. For example, “wel” = “lew“.

AIM:

          To create a reverse of the given string

CODING:

def rev(str1):

str2=”

i=len(str1)-1

while i>=0:

str2+=str1[i]

i-=1

return str2

word=input(“\n Enter a string:”)

print(“\n The mirror of the string is:”, rev(word))

OUTPUT:

Enter a string: wel

The mirror of the string is: lew

RESULT:

The Output was verified successfully

Accessing characters in a String

  • Once you define a string, python allocate an index value for its each character.
  • These index values are otherwise called as subscript which are used to access and manipulate the strings.
  • The subscript can be positive or negative integer numbers.
  • The positive subscript 0 is assigned to the first character and n-1 to the last character, where n is the number of characters in the string.
  • The negative index assigned from the last character to the first character in reverse order begins with -1.

Tags:

Practical

Share Article

Follow Me Written By

Baskaran J

Other Articles

Previous

How to get centum-pass in 12th computer science-computer applications for public exam 2023?

Next

Practical program exercise 1 page formatting for 12th computer applications

Next
February 7, 2023

Practical program exercise 1 page formatting for 12th computer applications

Previous
February 6, 2023

How to get centum-pass in 12th computer science-computer applications for public exam 2023?

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

twenty − eighteen =

Related Posts

12th CS Board Exam Answer Key Discussion 2024-2025

Baskaran J
March 14, 2025

12th Computer Science English medium Program Question 2024-2025

Baskaran J
February 23, 2025

12th Computer Science Practice One marks question 2024-2025

Baskaran J
February 3, 2025

12th Computer Science English medium Public Exam Important Important Question 2024-2025

Baskaran J
January 16, 2025

Subscribe to our newsletter and stay updated.

CS Knowledge Opener

CS Knowledge Opener focuses on 11th &12th Computer Science & Computer Applications English Medium & Tamil Medium. Programming Skills and also we are Publishing Study Materials Based on New syllabus introduced by TNSCERT. (TNBOARD).

Quick Links

  • Contact Us
  • About Us
  • Privacy Policy
  • Disclaimer
  • Terms and Conditions
Categories
11th CA English Medium 15
11th CA Tamil Medium 9
11th CS English Medium 21
11th CS Tamil Medium 12
12th CA English Medium 32
12th CA Tamil Medium 8
12th CS English Medium 36
12th CS Tamil Medium 12
Government Exams 36
Notifications 8
Other Subjects 13

Follow Us

Youtube
Facebook
Telegram
CS Knowledge Opener © 2020 - 2025. All Rights Reserved.