Hey guys,
I have some Java code here, which checks whether a word is present in a sentence or not:
import java.io.*;
class search_arrays
{
static void search()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence: ");
String s=br.readLine();
s+=" ";
String[] x=new String[s.length()];
int a=0,b=0;
for(int i=0;i<x.length;i++)
{
if(s.charAt(i)==' ')
{
x[a]=s.substring(b,i);
a++;
b=i+1;
}
}
System.out.println("\nEnter a word you want to search for: ");
s=br.readLine();
boolean ans=false;
for(int i=0;i<x.length;i++)
{
if(s.equalsIgnoreCase(x[i]))
{
ans=true;
}
}
if(ans)
{
System.out.println("\n"+s+" has been entered.");
}
else
{
System.out.println(s+" has not been entered.");
}
}
}
Now, can this be done in Python? Can anyone give me the basic idea of how I can go about this? (No, this is NOT homework!)
Thanks