1

I made this function and I want to adapt it to take two parameters. One for the letter and one for the number. The function should print the appropriate amount of letters. (e.g. If the user types "monkey" and "3" the function will output "mon")

So far this is my code

word = input ("What is your word?")
number = input ("What is your number? ")
def test():

    letter=word[0]
    print (letter)

test()
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Jakus
  • 9
  • 3

2 Answers2

2

Is that what you want?

word = input("What is your word?")
number = int(input("What is your number? "))

def test(word, number):
    print(word[:number])

test(word, number)

Result:

What is your word?monkey    
What is your number? 3    
mon
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Julien
  • 13,986
  • 5
  • 29
  • 53
0
word = input ("What is your word: ")
number = input ("What is your number: ")

def test():
    print(word[:int(number)])

test()

This should not give you your syntax error that you mentioned in Julien Bernu's question.

Note: This is assuming you are using the latest version of python

Liwa
  • 116
  • 12