• Register
0 votes
68 views

I am newbee and I was trying some codes in python, I wrote a code in python to count how many times a word appears in a string  :

string = "Not Your buisness surely not your"

CountString = string.count("buisness" 0, 6)
print("CountString")

It shows an error message:

File "main.py", line 3
    CountString = string.count("buisness" 0, 6)
                                          ^
SyntaxError: invalid syntax

why am I getting this type of error message and how can I check how many times a word appears in a string?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

To count how many times a word appears in string  you used 

count()

method .That was right but you should have write your code:

string = "Not Your buisness surely not your"


print(string.count("Not", 0, 20))
print(string.count("Your", 0, 20))
print(string.count("buisness", 0, 20))
print(string.count("surely", 0, 20))
print(string.count("not", 0, 20))
print(string.count("your", 0, 20))

In this format. You should get an output like:

1
1
1
0
0
0

Happy Coding.

11 6 4
34,950 points

Related questions

1 vote
1 answer 5 views
5 views
Problem: Please help me. How can I solve it? python count how many times a word appears in a string
asked Mar 30 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 7 views
7 views
Problem: Any ideas on what I need to do to fix this? python count how many times a word appears in a list
asked Mar 30 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 8 views
8 views
Problem: Someone help me to fix this Please on > 'google sheets count how many times a word appears' ?
asked Mar 19 Samiur1 38.4k points
2 votes
1 answer 29 views
29 views
Problem: I just started learning java and solving problems from various online websites. Stuck on a problem saying, count how many times a substring appears in a string java. This problem is beyond my understanding. I found Kodlogs very helpful and friendly environment ... possible solution (with code snippet) would be great for me, and I must recognize your help. Thanks in advance, mate.
asked Mar 25, 2020 Gavin 15.3k points
0 votes
1 answer 6 views
6 views
Problem: I'm having trouble processing this error: It is required that the operation be exported or include an intent-filter “Count total number of times each alphabet appears in the string java program code with example”?
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 8 views
8 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Mar 30 tuhin1 48.9k points
0 votes
1 answer 5 views
5 views
Problem Need help for counting number of times substring appears in string python.
asked Apr 7 salim1 60.6k points
1 vote
1 answer 41 views
41 views
Problem: I am new in python programming language and I have been doing a online python course. I am doing my coding practice. I tried to check out in a string how many time word does exist or appear. I wrote this code to check this thing: test = "If you do not ... 3 Appearence = test.count("do" 0, 100) ^ SyntaxError: invalid syntax Can anyone help me out to solve this thing. Thank you in advance.
asked Apr 7, 2020 LizzyM 6.1k points
0 votes
1 answer 2 views
2 views
Problem: Please let me know any solution regarding this .. Excel count how many times a value appears in a column
asked Apr 26 Ifra 34.7k points
0 votes
1 answer 22 views
22 views
Problem: i need some help anyone who help please help sql count how many times a value appears in a column
asked Mar 17 Rohit kr 17.5k points