на вход программе подается одна строка. напишите программу, которая определяет сколько раз в строке встречаются символы + и *. in python

main.py
# take input string from user
string = input("Enter a string: ")

# initialize count variables for "+" and "*" 
plus_count = 0
star_count = 0

# loop through each character of the string
for 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:

  1. User inputs a string.
  2. The count variables for + and * are initialized.
  3. A for loop is used to iterate through each character of the string.
  4. Conditional statements check if the character is equal to "+" or "*", and increment the respective counter.
  5. The count of + and * is printed.

gistlibby LogSnag