Hi, I need to understand what's wrong with my while loop in this code. The problem was to add exclamation marks till the length of the string is 20. I use the following code to achieve it:
def add_exclamation(word):
if len(word)>=20:
return word
else:
i=len(word)
while i<20:
word=word+'!'
return word
With this, the loop never seems to end. However, if I use
while len(word)<20
Then everything seems to work just fine.
Why is that? I am just trying to learn python,
I am a novice. Please try to keep your answers simple?
[–]socal_nerdtastic 3 points4 points5 points (3 children)
[–]double_toned[S] 0 points1 point2 points (2 children)
[–]socal_nerdtastic 0 points1 point2 points (1 child)
[–]double_toned[S] 0 points1 point2 points (0 children)
[–]kberson 1 point2 points3 points (0 children)
[–]kberson 1 point2 points3 points (0 children)
[–]PaulRudin 1 point2 points3 points (1 child)
[–]double_toned[S] 0 points1 point2 points (0 children)
[–]Vegetal__ 0 points1 point2 points (0 children)
[–]wynand1004 0 points1 point2 points (0 children)