CAN YOU HELP ME WITH THIS PYTHON TASK====1.based on the variable: str1="one two three twenty one thirty one fifty one" and the help of one or more string management methods, you are asked to check if it contains more than twice the string 'one'. If yes, then the program should say "More than Two". IF not , then the program should say "There are fewer than two"
Asked
Active
Viewed 32 times
-4
-
2If you have a specific question post the relevant code and ask the question, if you are just looking for someone to do it for you you are in the wrong place. – Guy Dec 31 '19 at 09:41
-
So... What's the problem? SO is not a code-writing service, we can only help you with concrete problems when you show us your code. If you need a hint: think how would you do this on paper. There are more possible solutions to this, but this is the simplest thing you can code. – h4z3 Dec 31 '19 at 09:41
-
1First you should try to solve it, and provide the code you are trying. – Banukobhan Nagendram Dec 31 '19 at 09:44
-
I ll use the variable : string1.count("one") but I don t know which variable should I choose to check if There are MORE than two "one" ..I know all the other task. Only that is confusing me . – Παναγιώτης Φασουλίδης Dec 31 '19 at 09:51
-
https://stackoverflow.com/questions/4664850/how-to-find-all-occurrences-of-a-substring – Ardweaden Dec 31 '19 at 09:57
1 Answers
-1
Here is the solution:
str1="one two three twenty thirty fifty one"
if str1.count("one") > 2:
print("More than Two")
else:
print("There are fewer than two")

Vaibhav Jadhav
- 2,020
- 1
- 7
- 20
-
Thank you Vaibhav Jadhav..It was simple and I was confused. You' re great!! – Παναγιώτης Φασουλίδης Dec 31 '19 at 10:21
-
@ΠαναγιώτηςΦασουλίδης Welcome. Try it and you will get it step by step. :-) – Vaibhav Jadhav Dec 31 '19 at 10:23
-