0
How to improve my âwhileâ function
str = input() print(len(str)) x=0 y="1" while x<len(str): print(str[x]+(y)) if str[x]==" ": if y=="1": y="2" elif y=="2": y="3" #etc x=x+1
9 Answers
0
I got it fixed
s = input()
print(len(s))
x=0
y=1
while x<len(s):
print(s[x]+str(y))
if s[x]==" ":
y+=1
x=x+1
End program
Thanks for your help
+ 10
@Baptiste...
right...
I also said it.
+ 9
str is a python function..
you define str as a variable.
again you call str() function.
when you call str like function, you will face a error.
that time ask yourself...
a variable is callable?
you should know rules of defining a variable.
+ 4
s = input()
print(len(s))
x=0
y=1
while x<len(s):
print(s[x]+str(y))
y = y + 1
x=x+1
I had to rename your string as str is a function to cast an object to string. You override it in your code but needed it
+ 3
@KäzÎ, it is legal to do so in python and as he did not call it as a function, no problem
+ 1
Good idea @~ swim ~
- 1
s = input()
print(len(s))
x=0
y=1
while x<len(s):
print(s[x]+str(y))
y+=(s[x]==" ")
x=x+1
y=str(y)
Even better without while
s=input()
y=str(sum(c==" " for c in s))
or even y=str(input().count(" "))
Str is a python keyword. Confusing to name a var after it.
- 1
still awfully long. use what python offers !