Ask coding questions

← Back to all posts
can someone explain this in details
h
GermanTs (0)

i made research and find this kind of code from google for my project. im newbie in python so can someone help me and explain this in details? https://repl.it/@GermanTs/TAG

Commentshotnewtop
malvoliothegood (195)
# Get text string input from the user and store it in a variable called "var"
var = input('any: ')
# Find how many characters there are in "var"
lenght = len(var)
# Find the index value of the middle of the string
middle = int(lenght / 2)
# If the numbers of characters in "var" is even display the middle two characters 
if lenght % 2 == 0:
  print(var[middle-1 :middle+1])
else: # Display the middle chacter
  print(var[middle :middle+1])

Read more: https://www.tutorialspoint.com/python/python_strings.htm

GermanTs (0)

@malvoliothegood thanks ! that was so helpful .