19 Jan 2015

Longest substring in Alphabetical order

#Python ''' Find the longest substring in alphabetical order in the given string ''' s = 'azcbobobegghakl' i=1subs=s[0]subs2=s[0]while(i<len(s)):    j=i    while(j<len(s)):        if(s[j]>=s[j-1]):            subs+=s[j]           ...

Categories: , ,

Count of Substring in String

#Python ''' Count the number of times the substring 'bob' appears in string s ''' s='azcbobobegghakl'i=0ocr=0while(i<(len(s)-2)):    ocr+=s.count('bob',i,i+3)    i+=1       print "Number of times bob occurs is:", ocr     ...

Categories: ,

Counting Vowels

#Python ''' The program counts number of vowels in a string s ''' s = 'azcbobobegghakl' s=s.lower()count=0i=0while (i<len(s)):    if (s[i] in 'aeiou'):        count+=1    i+=1print "Number of vowels", count    &nbs...

Categories: , ,

Number Guessing game

#Python ''' Number Guessing Game '''   print "Please think of a number between 0 and 100!"start=0end=100guess=50while(1):    print "Is your secret number",guess, "?"    rd=raw_input("Enter 'h' to indicate the guess ls too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")   ...

Categories: , , ,

Copyright © 2025 UPgradeCODING | Powered by Blogger