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")
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)