Python 3


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)

PAGE 1 / 1
Strings in Python
Home >>> Online Lessons, Python 3

Proposed Problems

For a better understanding, solve the following tasks.
1. Write a program that reads a string from the keyboard and displays how many times the letter "a" appears in the text.

Example. For "Mark goes to the beach." it will display 2.

Solution. Simple – using the count() method:

s = input()

Suggested Exercise. Write a similar program that displays how many times each vowel in the English alphabet appears in the text read, and then, at the end, the total number of their occurrences.

2. Write a program that reads a string from the keyboard and displays the following information:

a) the length of the string
b) if there is any occurrence of the consonant "x"
c) if the string starts with "a" or "A"
d) if the string ends with "."

3. Check if a given string read from the keyboard has a length greater than 20.

Example. For "Eric is a smart boy in the seventh grade." it will display True.

4. Given a city name, a country, and a number, display a custom message.

Example. For "Paris", "France" and "7" it printed "Great! I have also visited France, and in Paris, I had a wonderful time for 7 days".

5. Read a string from the keyboard and print it in uppercase, read from right to left.

6. Given a string, display whether the first character is identical to the last one (True/False).

Pay attention to how you request the information.
Pay attention to how you present the processed information.
Editor -
Console/Output done
 home   list  CONTENTS   perm_identity   arrow_upward