HACKING 120% {Hacking, programmazione, computer & molto altro}

Primamide di lettere

« Older   Newer »
  Share  
view post Posted on 2/4/2012, 20:11     +1   -1
Avatar

Water can take unforseen forms.

Group:
Founder
Posts:
5,273
Reputation:
+1,147
Location:
Shabang

Status:


Vabbè, un esercizietto veloce veloce..

Creare degli algoritmi, tali che su input "wet" diano:

Pir1:

w
we
wet
we
w

Pir2:

w
we
wet
tew
ew
e

Pir3:

wet
et
t
t
te
tew




Dopo posto le mie soluzioni

Edited by Wet Water - 2/4/2012, 21:38
 
Web  Top
view post Posted on 2/4/2012, 21:02     +1   -1
Avatar

Water can take unforseen forms.

Group:
Founder
Posts:
5,273
Reputation:
+1,147
Location:
Shabang

Status:


CODICE
def pir1(word):
   for x in range(len(word)+1):
       print word[:x]
   for x in range(len(word)+1):
       print word[:-x-1]

def pir2(word):
   for x in range(len(word)+1):
       print word[:x]
   print word[::-1]
   for x in range(len(word)):
       print word[::-1][:-x-1]
     
def pir3(word):
   for x in range(len(word)):
       print word[x:]
   for x in range(1,len(word)+1):
       print word[::-1][:x]
   
word=raw_input("Parola: ")
pir1(word)
print
pir2(word)
print
pir3(word)
 
Web  Top
1 replies since 2/4/2012, 20:10   84 views
  Share