0

Hi, im newish to python and have been stuck on this coding for a few days

I have managed to code so I take input from user of a string which I then list the string depending on how many strings are entered after a space

so if the input was "hello jacob"
my code would output
hello
jacob

now I wish to add to the code to allow me to calculate the longest and shortest strings that is input by the user.
---------------------------------

my code for the first task is:
m = input("Enter a string ")
____i = 0
____m=m+" "
____while m==" ": i=i+1
____while i<len(m)-1 :
________word = ""
________while m==" ": i=i+1
________while m != " " :
____________word = word + m
____________i=i+1
________print(word)

If anybody could offer abit of advice I'd be grateful.
Thanks.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by woooee
1

Some print statements should help. Note that "word" will only contain the final word in a sentence. Once you can get each word, add a counter to count the letters as they are added to the new "word" field or what ever you wish to use.

m = input("Enter a string ")
i = 0
m=m+" "
while m[i]==" ": i=i+1
print("#1 i =", i)
print ()
print("while i<len(m)-1-->", i, "< ", len(m)-1)
while i<len(m)-1 :
    print "     i in while =", i
    word = ""
    while m[i]==" ": i=i+1
    while m[i] != " " :
        word = word + m[i]
        i=i+1
print("final print", word, "i =", i)

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.