can you please change the following C language code in python language I also posted the output of the following code

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter6: Sub And Function Procedures
Section: Chapter Questions
Problem 10E
icon
Related questions
Question

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;
}

O CAUsers\Ali Computers\Desktop\Project1.exe
Enter the length of the string:6
enter the string: abc123
Rejected
Process exited after 6.091 seconds with return value 0
Press any key to continue
Transcribed Image Text:O CAUsers\Ali Computers\Desktop\Project1.exe Enter the length of the string:6 enter the string: abc123 Rejected Process exited after 6.091 seconds with return value 0 Press any key to continue
C:\Users\Ali Computers\Desktop\Project1.exe
Enter the length of the string:6
enter the string:101011
ассеpted
Process exited after 8.979 seconds with return value 0
Press any key to continue
30
{flag-0;
Transcribed Image Text:C:\Users\Ali Computers\Desktop\Project1.exe Enter the length of the string:6 enter the string:101011 ассеpted Process exited after 8.979 seconds with return value 0 Press any key to continue 30 {flag-0;
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Name constants and Literal values
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning