Answer to Question #281951 in Python for ally

Question #281951

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.


Are you up for the challenge?

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.
1
Expert's answer
2021-12-22T14:24:22-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 rocks')

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