+ 2
Please correct my code
You are building a search system and need to search for the character 'a' in an input string. Output "Match" if 'a' is found in the string, and "No match" if it's not. Sample Input great Sample Output Match --------MY CODE------ search = input() #your code goes here alpha = "a" if "a" in search == "a" in alpha: print("Match") else: print("No match")
11 ответов
+ 7
Try this:
Then input "asd".
https://code.sololearn.com/cbO030R919SG/?ref=app
+ 6
if alpha in search:
# or
if "a" in search:
+ 2
It's still bringing back no match on asd
+ 2
Thank you guys
+ 1
Thanks 👍
+ 1
👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
+ 1
s = input()
if "a" in s:
print("Match")
else:
print("No match")
0
search = input()
alpha = "a"
if alpha in search:
print("Match")
else:
print("No match")
0
#include<iostream>
using namespace std;
int firstoccurance(int nums[],int n,int target){
int start = 0;
int end = n-1;
int mid = start +(end - start)/2;
int ans = -1;
while (start<=end)
{
if (target==nums[mid])
{
return mid;
end = mid-1;
}else if (target<nums[mid])
{
end = mid-1;
}
else
{
start = mid +1;
}
mid = start +(end - start)/2;
}
return ans;
}
int lastoccurance(int nums[],int n,int target){
int start = 0;
int end = n-1;
int mid = start + (end - start);
int ans = -1;
while (start<=end)
{
if (target==nums[mid])
{
ans = mid;
start = mid+1;
}else if (target<nums[mid])
{
end = mid -1;
}
else
{
start = mid +1;
}
mid = start + (end - start)/2;
}
return ans;
}
int main(){
int nums[10] = {2,5,5,5,6,6};
int index = firstoccurance(nums,10,5);
cout<<"The firstoccurance element size is:"<<index<<endl;
cout<<"The lastoccurance element size is "<<index<<endl;
}