Skip to main content

Python Basic Program-Palindrome

Python Palindrome:
Input:a string (Mom)
Output:Mom is a palindrome
Input:a string (Monk)
Output:Monk is not a palindrome
Expalanation:
   1)The string "Mom" when reversed produces a same word "moM",so it is a palindrome.
    2)The string "Monk" when reversed produces a different word"knoM",so it is not a palindrome.


Program 1:
def palindrome(p):
    word=p.lower()
    a,*b,c=word
    word1=c,*b,a
    if list(word)==list(word1):
        return "Palindrome"
    else:
        return "Not a palindrome"

word=input("Enter a word:")
result=palindrome(word)
print(f"{word} is  {result}")
Output:
Enter a word:Mom
Mom is  Palindrome
Enter a word:Monk
Monk is Not a Palindrome
Program 2:using reverse index
def palindrome(p):
    word=p.lower()
    if word==word[::-1]:
        return "Palindrome"
    else:
        return "Not a palindrome"

word=input("Enter a word:")
result=palindrome(word)
print(f"{word} is  {result}")
Output:
Enter a word:Mom
Mom is  Palindrome
Enter a word:Monk
Monk is Not a Palindrome
Program 3:using reversed function
def palindrome(p):
    word=p.lower()
    word1=''.join(reversed(word))
    if word1==word:
        return " a Palindrome"
    else:
        return "Not a palindrome"

word=input("Enter a word:")
result=palindrome(word)
print(f"{word} is {result}")
Output:
Enter a word:Mom
Mom is a Palindrome
Enter a word:Monk
Monk is Not a Palindrome
Do check out the video below to know more about python!!
Happy Learning!!

Comments

  1. #include // your first cc+ programming headers
    using namespace std; // namespace.

    int main ()

    {
    cout << "hello welcome to c++";

    // new lines!!
    // example

    cout << "hello world \n";
    cout << "I love programming \n" << "I love cc+ \n ";
    // new line end$$






    // comments!!
    // example

    // pribnt// COMMENTS $
    cout << "comments " << endl;
    // comments have have another example
    // example
    /* if you type a comments single line use (/ /) or
    are if you want multi comments use (/* */

    //comments end$$





    // VARIABLES!!
    // example
    int myvariable = 10;
    cout << myvariable << endl ;
    //defines two variables of type int
    //int a, b


    int a = 55;
    int b;
    b = 5;
    int a1 , b1 ;
    int a2 = 5 , b2 = 5;
    cout << a + a2 * b;



    // program (2add) 2div (*5ans)
    int n1 , n2;
    n1 = 50 , n2 = 100 ;
    int addvalue = n1 + n2;
    int divvalue = n1/n2;

    int finalvalues1 = addvalue*5;
    int finalvalues2 = divvalue*5;




    return 0;
    }


    OUTPUT

    hello welcome to c++hello world
    I love programming
    I love cc+
    comments
    10
    80

    !!!!Bro na c ++ comment potu iruka python la sorry bro unga ketathu, athu learn panathuu bRO

    ReplyDelete
  2. // Online C++ compiler to run C++ program online
    #include

    int main() {
    char name, dept, college;
    std::cout<<"what is your name";
    std::cin>>name;
    std::cout<<"which dept your";
    std::cin>>dept;
    std::cout<<"which college your";
    std::cin>>college;
    int mark1, mark2, mark3;
    std::cout << "enter the mark1,coutmark2 and mark3";
    std::cin >> mark1>>mark2>> mark3;
    std::cout << mark1+mark2+mark3;
    return 0;
    }

    ReplyDelete
    Replies
    1. // Online C++ compiler to run C++ program online
      #include

      int main() {
      char name, dept, college;
      std::cout<<"what is your name";
      std::cin>>name;
      std::cout<<"which dept your";
      std::cin>>dept;
      std::cout<<"which college your";
      std::cin>>college;
      int mark1, mark2, mark3;
      std::cout << "enter the mark1 mark2 and mark3
      Std::cin>> mark1>>mark2>> mark3;
      std::cout << mark1+mark2+mark3;
      return 0;
      }

      Delete
  3. Hi bro I am Hariharan C
    Am a new learner of C++ bro this is a program that you have gave a assignment in first video bro please check my program bro.
    Your teaching is just awesome bro.

    Here is my program bro .👇👇

    #include
    using namespace std;
    int main()
    {
    string name;
    int age , Tamil , English , Maths ;

    cout<<"Mark sheet";

    cout<<"\n"<<"Name :";
    cin>>name;

    cout<<"\n"<<"Age :";
    cin>>age;

    cout<<"\n"<<"Tamil :";
    cin>>Tamil;

    cout<<"\n"<<"English :";
    cin>>English;

    cout<<"\n"<<"Maths :";
    cin>>Maths;

    cout<<"Total marks :"<<Tamil+English+Maths;
    return 0;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Xplore-Know your TCS Solutions

KNOW YOUR TCS-SOLUTIONS 1.Who is the founder of Tata group? Jamsetji Tata 2.Which characteristics of Big Data deals with trustworthiness of data? Veracity 3.Which is India's first indigeneously designed and manufactured car? Tata Indica 4.What was originally called the "Imitation game" by its creator? The Turing test 5.90% of world's data is created in the last 2 years. True 6.In 1990s,which company did Tata steel acquire? Corus 7.How many independently operating companies are there under Tata group? Over 100 8.We use natural language processing for reviewing twitter fields. True 9.The change of mind set is required from "optimizing scarce resources" to "harnessing abundance" will help in? Leveraging ecosystems 10.Robots can be used for building houses. True 11.Which among the following key for IT management is based on the proper use of data? Embedding security in every system. 12.When did Tata Motors unveil Tata Nano? 2008 13.Business 4.0 brings