# Computer Programming using python

posted by .

Assume s is a string of lower case characters.

Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl', then your program should print

Longest substring in alphabetical order is: beggh
In the case of ties, print the first substring. For example, if s = 'abcbcd', then your program should print

Longest substring in alphabetical order is: abc
For problems such as these, do not include raw_input statements or define the variable s in any way. Our automating testing will provide a value of s for you - so the code you submit in the following box should assume s is already defined. If you are confused by this instruction, please review L2 Problems 10 and 11 before you begin this problem set.

Note: This problem is fairly challenging. We encourage you to work smart. If you've spent more than a few hours on this problem, we suggest that you move on to a different part of the course. If you have time, come back to this problem after you've had a break and cleared your head.

• Computer Programming using python -

DO IT BY YOURSELF OR YOU WILL NOT LEARN! GOOD LUCK!

• Computer Programming using python -

def test():
index = 1
prev_index = 0
count = 0
global largest
largest = ''
test = s[prev_index]

while count < len(s):
if ord(s[index]) > ord(s[prev_index]):
test += s[index]
index += 1
prev_index += 1
elif ord(s[index]) == ord(s[prev_index]):
test += s[index]
index += 1
prev_index += 1
else:
if len(largest) < len(test):
largest = test[:]
test = s[index]
prev_index += 1
index += 1
count += 1
return largest
try:
test()
except IndexError:
pass
finally:
print largest

## Respond to this Question

 First Name School Subject Your Answer

## Similar Questions

1. ### C++ programming computer

I'm having some trouble trying to program these problems and putting them into the main function. Please help me by giving some advice or website that offer good information for me. The questions are below here: 1. Write a function …
2. ### programming

How do you write a program that prints out your course schedule for a week?
3. ### Computer Programming using python

Assume s is a string of lower case characters. Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should …
4. ### Computer Programming using python

Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then your program should print Number of times bob occurs is: 2 For …
5. ### programming

Assume s is a string of lower case characters. Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should …
6. ### Python programming Language

Assume S is a string of lower case characters. Write a program that counts up the number of vowels contained in the string S. Valid vowels are 'a', 'e', 'I', 'o', and 'u'. For example, if S='azcbobobegghakl' your program should print: …
7. ### programming

Using python write a program that does the following: •Create the logic for a program whose main() method prompts a user for 1000 numbers and stores them in a list. •Pass the array to a method that reverses the order of the numbers. …
8. ### Computer science

Need help on how write this program. "The Eversoft Eraser Company has a list of its customers’ names (not necessarily in alphabetical order) and telephone numbers in a file named "customer" with records of the following form: last_name …
9. ### programming and visual basics

Using pseudocode or a flowchart write a program that does the following: Design the logic for the game Hangman, in which the user guesses letters in a hidden word. Store the letters of a word in an array of characters. Display a dash …
10. ### stats

A common computer programming rule is that names of variables must be between one and eight characters long. The first character can be any of the 26​ letters, while successive characters can be any of the 26 letters or any of the …

More Similar Questions