0

I'm new to python and I'm trying to count punctuation in a string input by user, and I"ve been able to do it w/ out a loop, but would like to emply a more efficiant method.
I've been able to loop through and grabb the characters, but they are'nt being displayed as a single value which is what I need so I can add this snipit to a larger piece of code.

here is my code:

str1 = input("Please enter a sentence:  ")
    
     
    for i in ["!","."]:
        g = str1.count(i)
        print(g)

Edited by as3g: n/a

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by as3g
0

This perhaps print(sum(str1.count(c) for c in ".!")) or sum(c in ".!" for c in str1)

Edited by Gribouillis: n/a

0

thanks keemosabee, works like "ballz marie"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.