Home > database >  Calculate the length of the string and print from the middle of the string
Calculate the length of the string and print from the middle of the string

Time:08-07

I am trying to perform the following but my code isn't working:

  • Take a string from user input
  • Calculate the length of the string and print from the middle of the string.
user_input = input("Enter a word: ")
x_user_input = str(user_input)
print(x_user_input[len(x_user_input)/2])

CodePudding user response:

If you want to print the string from position the middle to the end you have to do the following:

user_input = input("Enter a word: ")
x_user_input = str(user_input)
print(x_user_input[len(x_user_input)//2:])

CodePudding user response:

is this what you are trying to do?

user_input = input("Enter a word: ")
print(user_input[len(user_input//2):])
  • Related