# Written in python
a = int(input("Enter an integer: "))
b = int(input("Enter an integer: "))
sum = a + b
# subtract the smaller number from the bigger
if a < b:
dif = a - b
else:
dif = b - a
prod = a * b
print("The sum is", sum)
print("The dif is", dif)
print("The product is", prod)
This is for Python
name = 'Joe'
print(f'My name is {name}')
This is called string formatting. Using f before the text. This is another way
name = 'Joe'
print('My name is', Joe)
But I found that string formatting is cleaner and much more useful
Answer:
The code is given below. Follow the question and the code definitions for better understanding.
Explanation:
#include<iostream>
#include<string>
using namespace std;
int main(){
string pastWord="";
string currentWord,nextWord;
int n,t;
int singleton=0;
int consecutive=0;
cout<<"Enter words. ('xxxxx' to exit):\n";
cin>>nextWord;
do{
currentWord=nextWord;
cin>>nextWord;
if ( (currentWord!=pastWord)&&(currentWord!=nextWord) )
singleton++;
else if((currentWord==pastWord)&&(currentWord!=nextWord))
consecutive++;
pastWord=currentWord;
}while(nextWord!="xxxxx");
n=singleton;
t=consecutive;
cout<<"There were "<<n<<" singletons and "<<t<<" consecutive repetitions.";
cin.get();
return 0;
}