Skip to content

Commit a11f218

Browse files
committed
doc: add comments
Exercises manipulating text. First and last occurrence of a string.
1 parent 3c91f6f commit a11f218

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ex026.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
#First and last occurrence of a string
12
#26- Write a program that reads a sentence from the keyboard and shows how many times the letter "a" appears and in what position it is
23
# appears the first time and in what position it appears last time.
34
sentence = input('Enter a sentence:').upper()
45
print(f'The letter A shows {sentence.count('A')} times.')
56
print(f'The first letter A shows in position {sentence.find('A')+1}.')
67
print(f'The last letter A shows in position {sentence.rfind('A')+1}.')
8+
9+
10+
# Primeira e última ocorrência de uma string
11+
#26: Faça um programa que leia uma frase pelo teclado e mostre quantas vezes aparece a letra "A", em que posição ela aparece a
12+
# primeira vez e em que posição ela aparece a última vez.
13+
frase = str(input('Digite uma frase:')).upper()
14+
print(f'A letra A, aparece {frase.count('A')} vezes na frase.')
15+
print(f'A primeira letra "A" apareceu na {frase.find('A')+1} posição da frase.')
16+
print(f'A última letra "A" apareceu na {frase.rfind('A')+1} posição da frase.')
17+
18+
#PT- treinando a manipulação de strings.
19+
#EN- training string manipulation.

0 commit comments

Comments
 (0)