0
I want to make an algorithme which search a lettre or a number in a text
This is my programme char=input("what do you search:") text=input("in witch text,") def search(text,char): i=0 for c in text: if c==char: i+=1 print(i) Please can you try to find the mistake
4 Réponses
+ 2
Something like this?
char=input("what do you search:")
text=input("in witch text,")
def search(text,char):
i=0
for c in text:
if c in char:
i+=1
print(i)
search(text,char)
+ 1
Almost correct
Your search function only has to be called now. You just defined it, so nothing happens.
Instead of print use a return and print it in your main code like this:
char=input("what do you search:")
text=input("in witch text,")
def search(text,char):
i=0
for c in text:
if c==char:
i+=1
return i
print(search(text,char))
Also note that multiple input in Sololearn has to be given in advance, separated by new line
+ 1
iren yeger 1. Your function should return a result to be useful. Add return i in the end of the function. 2. The function should be called. Replace last string with print(search(text, char))
0
wow thank you Matthias