Semaine 4, jour 2
This commit is contained in:
28
Semaine_04/Exercices/exo_03.py
Normal file
28
Semaine_04/Exercices/exo_03.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
|
||||
input_string = input("Ecris un truc > ")
|
||||
|
||||
if len(input_string) == 0:
|
||||
print("Tu aurais pu participer.")
|
||||
sys.exit()
|
||||
|
||||
def return_string_infos(input_string: str):
|
||||
print("Tu as tapé : " + "\"" + input_string + "\"")
|
||||
print("Elle fait exactement " + str(len(input_string)) + " caractères.")
|
||||
print("EN MAJUSCULES, ELLE DONNE : " + "\"" + input_string.upper() + "\"")
|
||||
print("en minuscules, elle donne : " + "\"" + input_string.lower() + "\"")
|
||||
print("A l'envers, elle donne : " + "\"" + input_string[::-1] + "\"")
|
||||
|
||||
def replace_word_in_string(input_string: str, word_to_replace: str, word_replacement: str) -> str:
|
||||
print(f"Remplaçant \"{word_to_replace}\" par \"{word_replacement}\", cela donne : {input_string.replace(word_to_replace, word_replacement)}")
|
||||
|
||||
def count_occurences_in_string(input_string: str, occurence: str):
|
||||
print(f"L'occurence \"{occurence}\" apparaît {input_string.count(occurence)} fois.")
|
||||
|
||||
def strip_of_spaces(input_string: str):
|
||||
print(f"Sans les espaces de début et de fin, cela donne : {input_string.strip()}")
|
||||
|
||||
return_string_infos(input_string)
|
||||
replace_word_in_string(input_string, "vie", "mort")
|
||||
count_occurences_in_string(input_string, "e")
|
||||
strip_of_spaces(input_string)
|
||||
Reference in New Issue
Block a user