(python) Programming Little Practice

Source: Internet
Author: User

1, reverse a string of strings output, such as "ABCD" into "DCBA"

str1= "ABCD" Print Str1[::-1]

2, judge whether it is a palindrome--to determine whether the user input string is a palindrome. Palindrome refers to both positive and negative spellings are the same words, such as "racecar".

while (1):    input_str = raw_input (' Please input your string: ')    if input_str== "quit":        print "Bye"        break    elif input_str==input_str[::-1]:        print "Your input is Huiwen"    else:        print "Your input was not Huiwen"

3. Count the number of letters in an English sentence:

# ! Coding=utf-8txt="Failure is probably the fortification in your pole"count= {} for in txt:    count.setdefault (i,0)# If the dictionary does not have key I, The key is added, and the value of the key is set to 0. If you already have this key, do not change the dictionary    count[i]=count[i]+1Print count

4. Count the number of words in an English sentence:

#! Coding=utf-8txt= "Failure are probably the fortification in your pole are" strlist=txt.split ("") countword={}for I in Strlist:    Countword.setdefault (i,0)    countword[i]=countword[i]+1print Countword

  

(python) Programming Little Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.