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

1st Aug 2019, 5:30 PM
iren yeger
iren yeger - avatar
4 Respostas
+ 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)
1st Aug 2019, 5:41 PM
Steven M
Steven M - avatar
+ 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
1st Aug 2019, 5:38 PM
Matthias
Matthias - avatar
+ 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))
1st Aug 2019, 5:40 PM
portpass
0
wow thank you Matthias
1st Aug 2019, 5:44 PM
iren yeger
iren yeger - avatar