cat_dog

Requirements:

  • substrings and slicing

  • if, elif, else

  • loop through a string (while)

  • loop with an accumulator variable

Output True if the substrings "cat" and "dog" appear the same number of times in a string input by the user. Otherwise, output False.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

'catdog'

Output:

True

Test 2

Input:

'catcat'

Output:

False

Test 3

Input:

'1cat1cadodog'

Output:

True

Test 4

Input:

'catxxdogxxxdog'

Output:

False

Test 5

Input:

'catxdogxdogxcat'

Output:

True

Test 6

Input:

'catxdogxdogxca'

Output:

False

Test 7

Input:

'dogdogcat'

Output:

False

Test 8

Input:

'dogogcat'

Output:

True

Test 9

Input:

'dog'

Output:

False

Test 10

Input:

'cat'

Output:

False

Test 11

Input:

'ca'

Output:

True

Test 12

Input:

'c'

Output:

True

Test 13

Input:

''

Output:

True