ord() function: string - "ascll encoding
chr() function: ascll encoding - "string"
#Function
for i in range(ord( ' d ' ),ord( ' f ' )+1): #Get the ascll code values corresponding to d and f: range(100,102+1)
print (i) #Print 100,101,102 print
(chr(i)) # chr converts numbers to letters, prints d,e,f
Example:
There are three people a, b, c, and three iPhones d, e, and f! a said: my mobile phone is not d; b said: my mobile phone is not d and f
Q: Which mobile phone does each of the three hold?
for i in range(ord('d'),ord('f')+1):
for j in range(ord('d'), ord('f') + 1):
for k in range(ord('d'), ord('f') + 1):
if(i != j) and (i != k) and (j != k):
if (i != ord('d')) and (k != ord('d')) and (k != ord('f')):
print("a---%s b---%s c---%s" %(chr(i),chr(j),chr(k)))
Print result:
D:\untitled\1\venv\Scripts\python.exe D: /untitled/1/venv/main.py a---f b---d c---e Process finished with exit code 0