can you please change the following C language code in python language I also posted the output of the following code
can you please change the following C language code in python language
I also posted the output of the following code
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{ int n,l,i=0,flag=0;
char *A;
printf(" Enter the length of the string:");
scanf("%d",&n);
A=(char *)malloc(n*sizeof(char));
/* dynamicallly memory allocated for string , you can any length of string , which willbe created memory at run time */
printf("enter the string:");
scanf("%s",A);
l=strlen(A);/* this strlen function find the length of the string */
if(l>=3) /* length less than 3 will be rejected*/
{
while(A[i]!='\0') /* This while loop check all character of the string it must be '0' or '1' */
{
if(A[i]=='0'|| A[i]=='1')
{ flag=1; }
else
{ flag=0;
break;
}
++i;
}
}
else
{flag=0; }
if(flag==1)
{ printf(" accepted"); }
else
{ printf(" Rejected"); }
return 0;
}
Step by step
Solved in 3 steps with 1 images