Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

program that prompts user to enter string until string starts with "A" then prints longest string

Hi im trying to write a program where the user inputs multiple strings until a string begins with the letter "A". which then results in the console printing the longest string that was entered (ie, most characters entered in the string). I am struggling to work out how to achieve this as using letters instead of numbers has gotten the better of me.

The desired output is;

Enter a string: Faces all glow.
Enter a string: Time for summer fun 
Enter a string: As the happy faces show.
Longest string: "As the happy faces show."

find below my code ( note this code isn’t 100% accurate, can only get seem to get multiple inputs using the .split() function and there is no limit on how many strings can be entered, the string will end when the condition is met … meaning the string starts with the letter "A")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a, b, c, d, e, f, g = input("Enter seven values: ").split()
print("Enter a String: ", a)
print("Enter a String: ", b)
print("Enter a String: ", c)
print("Enter a String: ", d)
print("Enter a String: ", e)
print("Enter a String: ", f)
print("Enter a String: ", g)
print()

>Solution :

I must say what you are expecting and your sample code are not relevant at all. However, I think you are asking something like the following code can do

longestString = ""
a = " "
while a[0].capitalize() != 'A':
    a = input("Enter a String: ")
    if len(a) > len(longestString):
        longestString = a
    
print(longestString)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading