We can define a word as a group of characters without a space between them. To find the words of the input string , w can use split(delimiter) which returns a list of strings which had the defined delimiter between them in the input string.
def countWords(string):
words = string.split(" ")
count = len(words)
return count
Here we set the delimiter as the space character, and returned the length of the words list. I split each step into its own line for readability, however the function could be one line:
return len(string.split())
Here, no delimiter is specified. If one isn't given, it will default to split at any whitespace, including space.
Answer:
The work with city government is better than outside city government due to the reasons given below.
Explanation:
There are many differences while working in city government or outside city government. I choose city government job in data and digital service due to the following reasons.
- City government provides all types of facilities that are required in data management and digital services.
- Provision of more benefits along with salary from city government.
- City government arrange different training and development sessions for their employ.
- There are many learning and development opportunities, because they provide opportunity to work in different departments.
- City Government have better HR policies as compared to outside government.
Answer:
#include <iostream>
using namespace std;
void PrintPopcornTime (int bagOunces){
if (bagOunces < 2){
cout << "Too small"<<endl;
}
else if (bagOunces > 10){
cout << "Too large"<<endl;
}
else{
cout << bagOunces*6 <<" seconds"<<endl;
}
}
int main(){
PrintPopcornTime(7);
return 0;
}
Explanation:
Create a function called PrintPopcornTime that takes one parameter, bagOunces
Check the bagOunces using if-else structure. If it is smaller than 2, print "Too small". If it is greater than 10, print "Too large". Otherwise, calculate and print 6*bagOunces followed by " seconds".
Call the function in the main function with parameter 7. Since 7 is not smaller than 2 or not greater than 10, "42 seconds" will be printed.
The answer will be
97
98
96
194