python - Taking string for user then repeating a certain number of letters from that string as defined from the user -



python - Taking string for user then repeating a certain number of letters from that string as defined from the user -

def f11(): print(' hello! , welcome the') print(' letter repetition script!!') print('--------------------------------------------') x= input('enter word: ') y= int(input('enter number: ')) z= int(input('enter amount of times want letters repeated: ')) if len(x) > 0 , x.isalpha(): x[0:y:1]== letter letter * z== new_word print(new_word) else: print('error no word input') f11() f11()

im trying take string , 2 integers, x = string y= number of letters word , z amount of times should repeated

for example:

x= hello

y=2

z=4

output= hehehehe

the problem im having line

x[0:y:1]== letter

is not working

thanks

you can utilize piece notation grab part of string interested in, utilize * operator repeat substring.

def repeatletters(word, dist, rep): homecoming word[:dist] * rep >>> repeatletters('hello', 3, 4) 'helhelhelhel'

note used abbreviated piece notation

[:dist]

which equivalent to

[0 : dist : 1]

edit side note, you've got python syntax misunderstandings. @ these lines example.

x[0:y:1] == letter letter * z== new_word

the == operator equality check, says "does left hand side equal right hand side?". not assignment operator, =. beingness said, if did utilize assignment operator, must assign right left, example

new_word = letter * z

python

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -