Python Forum
Print the longest str from user input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print the longest str from user input
#4
Some observations about your code:

- input is string, so no need to use str() for converting
- no need to define n before while loop. Use instead 'while True' and break
- use Larz60+ advice - append user answers to list and print out longest

As this is homework I provide 3.8-only compatible solution which probably will not pass automagic check but gives general idea:

values = []                                             # list to collect user entered strings
while (answer := input('Enter input: ')) != '':         # while loop which assigns user input to answer and checks equality to ''
    values.append(answer)                               # appends answers to values list

print(f'Longest input was {max(values, key=len)}')      # prints out longest element in values list
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Print the longest str from user input - by edwdas - Nov-04-2019, 09:42 AM
RE: Print the longest str from user input - by perfringo - Nov-04-2019, 11:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,366 Nov-12-2022, 03:47 AM
Last Post: deanhystad
Sad Find Longest streak for habits johnconar 3 1,985 Sep-12-2022, 07:13 PM
Last Post: deanhystad
Bug How to print only vowels from an input? PP9044 8 7,804 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Print user input into triangle djtjhokie 1 2,483 Nov-07-2020, 07:01 PM
Last Post: buran
  Changing Directory based on user input paulmerton4pope 13 8,317 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  how to add the user input from file into list wilson20 8 4,433 May-03-2020, 10:52 PM
Last Post: Larz60+
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,624 Feb-27-2020, 09:22 AM
Last Post: buran
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,913 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,147 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,584 Mar-23-2019, 06:54 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020