Answer to Question #284925 in Python for Jhonny

Question #284925

1. Finding Letters

by CodeChum Admin

We've already counted digits before on a certain number, so how about doing it on strings and characters? There's a catch, though, since you're only going to count and see if the character exists at least twice in a string.


Instructions:

  1. Create two variables and assign them to an input() function. The first variable shall accept a single letter and the second variable shall store the inputted string.
  2. Using loops, count the number of times that the single letter appears on the inputted string, and when it appears at least twice in the string, print "Cody is really awesome"; else, print "Cody rocks".
  3. Tip: to make your code more efficient, use the break keyword to terminate the loop whenever the count of appearance of the single letter has already reached 2.

Input

The first line contains a single-letter string.

The second line contains a string.

e
CodeChum·is·awesome

Output

A line containing a string.

Cody·is·really·awesome




1
Expert's answer
2022-01-05T16:25:54-0500
s = input()
l = input()
c ​=0
for ​i in s:
    if c ==2:
        break
    if i == l:
        c += 1
if ​c>=2:
    print('Cody is really awesome')
else:
    print('Cody rock')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS