• Register
0 votes

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)

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 


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:


Happy Coding.

11 6 4
34,950 points

Related questions

2 votes
1 answer 20 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
1 vote
1 answer 37 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
1 vote
1 answer 43 views
Problem: I have a list that contains the values: list = [2, 4, 8, 16, 32, 2, 64, 128, 2, 256, 512, 2] I wrote a python program for this where I could find out how many times a value appears in a list python: def count_appearence(list, z): check = ... count_appearence(list, z))) NameError: name 'z' is not defined What is the problem with my code. Please help me solve this thing. Thanks in advance.
asked May 13, 2020 samhaz 5k points
2 votes
1 answer 22 views
Problem: I was trying to find the first repeated word in a string in python using dictionary. So I wrote this code which give me error. def whichRepeat(input): words = input.split(' ') dict = words for key in words: if dict[key]>1: print (key) return if __name__ == ... "main.py", line 10, in whichRepeat if dict[key]>1: TypeError: list indices must be integers or slices, not str How to solve this?
asked Apr 28, 2020 samhaz 5k points
0 votes
1 answer 26 views
How to get the number from the occurences of individual characters Supose the string is: x = 'cdfghcfonccn' How can i solve this problem.
asked Mar 10, 2020 LizzyM 6.1k points
0 votes
1 answer 12 views
I require to remove all the special characters, puntuation and and speces from a string?
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 21 views
Problem: Hello kodlogs, Recently while attempting, the problem in the python there is a error that came can you please help sort out this problem, How can I get the first character from the first string in Python?,It seems that I could use list[0][1:] but that does not give me the first character of the string that I am looking for. mysrt = "sdf" >>> mystr[0][1:]
asked Jun 6, 2020 Gavin 15.3k points
1 vote
2 answers 38 views
Problem: I am very noob at programming language so I am doing my pracice on python. I tried to to replace multiple characters in a string in python. So I write this code: tes_str = "abababababababba" print("The main string is : " + str(tes_str)) res = tes_str('a', '%temp%')('b', ... = tes_str('a', '%temp%')('b', 'a')('%temp%', 'b') TypeError: 'str' object is not callable Can anyone help me out?
asked Apr 6, 2020 LizzyM 6.1k points
2 votes
1 answer 30 views
Problem: Well, let’s assume I have a string in python and I am willing to remove all the duplicates characters from my string. Suppose my string is “Australia” the program should return “Austrli” So, my question is simple. How can I remove duplicate characters in a string python?
asked Apr 5, 2020 Gavin 15.3k points
1 vote
1 answer 19 views
Problem: I tried to count occurrences of individual character of string using python. So I wrote this program for the string: a = 'yanwawny' The program: ​​​string = 'yanwawny' ​dict((letter, string.count(letter)) for letter in set(a) But it throws the error message: File "main.py", line 1 ​a = 'yanwawny' ^ SyntaxError: invalid character in identifier What to do to solve this thing?
asked May 4, 2020 samhaz 5k points