DEV Community

Md. Taosif
Md. Taosif

Posted on

assignment

Write a Python program that will ask the user to enter a word as an input.

● If the length of the input string is less than 4, then your program should print the same
string as an output.
● If the input string’s length is greater than 3, then your program should add "er" at the end
of the input string.
● If the input string already ends with "er", then add "est" instead, regardless of the length
of the input string
● If the input string already ends with "est", then your program should print the same input
string as an output.

include

using namespace std;

int main() {
string a;
cin>>a;
string e;
int i =a.length()-1;
int j =a.length()-2;
int k =a.length()-3;
if (a.length()<4){
if (a[i]=='r' and a[j]=='e'){
e=a.substr(0,j);
cout< }
else{
cout< }
}
else if (a.length()>3){
if (a[i]=='r' and a[j]=='e'){
e=a.substr(0,j);
cout<<e+"est";
}
else if(a[i]=='t' and a[j]=='s'){
if(a[k]=='e'){
cout<<a;
}
else{
;
}
}
else{
cout<<a+"er";
}
}

return 0;
Enter fullscreen mode Exit fullscreen mode

Write a program that takes a string as input and prints “Binary Number” if the string contains
only 0s or 1s. Otherwise, print “Not a Binary Number”.

include

using namespace std;
int main(){
string a;
cin>>a;
int flag=0;

for(int i=0;i<=a.length();i++){
    if (a[i]=='1' or a[i]=='0'){
        flag=flag+1;
    }
}
if (flag==a.length()){
    cout<<"binary";
}
else{
    cout<<"not binary";
}


return 0;
Enter fullscreen mode Exit fullscreen mode

}
}

########################Write a Python program that will ask the user to input a string (containing exactly one word).

Then your program should print subsequent substrings of the given string as shown in the
examples below

include

using namespace std;

int main() {
string a;
cin>>a;
string e;
for(int i =0;i<=a.length();i++){
e=a.substr(0,i);
cout<<e<<endl;
}

return 0;
Enter fullscreen mode Exit fullscreen mode

Write a Python program that will ask the user to input a string (containing exactly one word).
Then print the ASCII code for each character in the String using the ord() function.
To check if your program is working correctly or not, you can find a list of all correct values
from the following website. You may look at “Dec” and “Char” columns only and ignore the
other columns for this problem.

include

using namespace std;

int main() {
string a;
cin>>a;
char b=' ';
for (int i =0;i<=a.length();i++){
b=a[i];
cout<<(int)b<<endl;
b=' ';
}

return 0;
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)