на вход программе подается одна строка. напишите программу, которая определяет сколько раз в строке встречаются символы + и *. in python
main.py
# take input string from userstring = input("Enter a string: ")
# initialize count variables for "+" and "*" plus_count = 0star_count = 0# loop through each character of the stringfor char in string:
# if the character is +if char == '+':
plus_count += 1# if the character is *elif char == '*':
star_count += 1# print the count of + and *print("Count of + in the string:", plus_count)
print("Count of * in the string:", star_count)
487 chars
22 lines
Explanation:
User inputs a string.
The count variables for + and * are initialized.
A for loop is used to iterate through each character of the string.
Conditional statements check if the character is equal to "+" or "*", and increment the respective counter.