Character Classification based on ASCII value

SingleCharacter = input("Enter a character:",)
Character = ord(SingleCharacter)
# ord --> Convert a string to ASCII value
if Character > 0 and Character <= 31:
    print("ASCII value", Character," is a control character")
elif Character >= 48 and Character <= 57:
    print("ASCII value", Character,"  is a character is a digit")
elif Character >= 65 and Character <= 90:
    print("ASCII value", Character,"  is a uppercase letter")
elif Character >= 97 and Character <= 122:
    print("ASCII value", Character,"  is a lowercase letter")
else:
    print("ASCII value", Character," is a Symbol")

To find the distance between two points, given by the coordinates (x1, y1) and (x2, y2) by Pythagorean theorem using functions

def pt(x1,y1,x2,y2):
      x=x2-x1
      y=y2-y1
      x=x**2
      y=y**2
      d=(x+y)**(0.5)
      return d
     
x1=int(raw_input('Enter the coordinate x1: '))
x2=int(raw_input('Enter the coordinate x2: '))
y1=int(raw_input('Enter the coordinate y1: '))
y2=int(raw_input('Enter the coordinate y2: '))
k=pt(x1,y1,x2,y2)
print 'Distance between two points is : ', k
     

Database version retrieving using Python

#username of MySQL: root
#Password: root
#Hostname: localhost
# Database Name in MySQL: test

import mysql.connector
x = mysql.connector.connect(user='root', password='root',host='localhost',database='test')
# prepare a cursor object using cursor() method
cursor = x.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print ("Database version : %s " % data)
# disconnect from server
x.close()

Database connection test to MySQL

#username of MySQL: root

#Password: root

#Hostname: localhost

# Database Name in MySQL: test

import mysql.connector

x = mysql.connector.connect(user='root', password='root',host='localhost',database='test')

x.close()

Reversal of a string

startmsg = "hello"
endmsg = ""
for i in range(0,len(startmsg)):
  endmsg = startmsg[i] + endmsg
print (endmsg)