28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
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) |