Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0157 - Doar Vocale
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rezolvare == <syntaxhighlight lang="python" line="1"> # 0157 Doar Vocale def validare(nr_cuv, cuvinte): # functia de validare a datelor de intrare if nr_cuv <= 0 or nr_cuv >= 1000: raise ValueError if len(cuvinte) != nr_cuv: raise ValueError # daca datele de intrare nu corespund, ridicam eroarea ValueError for cuv in cuvinte: if len(cuv) > 30: raise ValueError for litera in cuv: if litera < 'a' or litera > 'z': # trebuie sa fie doar litera mica raise ValueError file_out.write("Datele de intrare corespund restrictiilor impuse\n") def vocala(litera): # functie care verifica daca litera este o vocala if litera in "aeiou": return True return False def doar_vocale(cuvinte): nr_cuvinte_doar_vocale = 0 # variabila in care numaram cate cuvinte contin doar vocale for cuv in cuvinte: are_consoane = False # presupunem ca fiecare cuvant nu are consoane for litera in cuv: if vocala(litera) is False: are_consoane = True # daca vreo litera din cuvant nu e vocala atunci are consoane break if are_consoane is False: # daca nu are consoane, numaram acel cuvant nr_cuvinte_doar_vocale += 1 file_out.write(str(nr_cuvinte_doar_vocale)) # afisarea if __name__ == '__main__': file_in = open("doarvocalein.txt", "r") # declararea fisierelor file_out = open("doarvocaleout.txt", "w") # fisierul out trebuie declarat cu optiunea "w" (write) # din cauza datelor de intrare pot aparea 2 tipuri de erori, valueError sau IndexError pe care le tratam try: nr_cuvinte = int(file_in.readline()) # citim numarul de cuvinte lista_cuvinte = [] # adaugam cuvintele intr-o lista for i in range(nr_cuvinte): cuvant = file_in.readline().strip() # fiecare cuvant il "curatam" de \n sau spatii de la final ce pot aparea in fisier apoi il adaugam in lista lista_cuvinte.append(cuvant) validare(nr_cuvinte, lista_cuvinte) # apelul functiei de validare doar_vocale(lista_cuvinte) # apelul functiei de rezolvare except ValueError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") except IndexError: file_out.write("Datele de intrare nu corespund restrictiilor impuse") </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width