CodeSolved

Solved Programming Questions & Exercises

Convert Persian to English numbers

Practice Easy 124/ Download 3720 Views Most popular

Write a function that receives a string and converts Persian numbers into English numbers

14 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
# Converting English numbers to Farsi and vice versa
# Farsi numbers are copied from Farsi Saz
num = {
    '0':'۰',
    '1':'۱',
    '2':'۲',
    '3':'۳',
    '4':'۴',
    '5':'۵',
    '6':'۶',
    '7':'۷',
    '8':'۸',
    '9':'۹'
}
# Changing the key position and values ​​in the above dictionary
rev = {v: k for k, v in num.items()} 
x = input('number:')
y = []
for char in x:
	y.append(char)
output = ''
if y[0] in num:       
	for char in x:
		output += num[char]
	print(output)
else:
	for char in x:
		output += rev[char]
	print(output)
Alvandsina Download Python
adad_farsi = ["۰"   ,"۱"    ,"۲"    ,"۳"    ,"۴",   "۵" ,"۶ ","۷","۸","۹"]
adad_english = ["0","1","2","3","4","5","6","7","8","9"]
def x(str):
    result = ""
    for c in str:
        index= adad_english.index(c)
        result += adad_farsi[index]
    return result
i = input("adad : ")
print(x(i))
User 5288 Download Python
def fa2en(input_string):
    output_string = ''.join([str(int(str(a))) if a.isdigit() else a for a in input_string])
    return output_string

text = 'امروز اسفند سال ۱۴۰۳ است، امروز ۲۱ ام است!'
print(fa2en(text))

User 3253 Download Python
def convert_persian_to_english(input_string):
    persian_to_english = str.maketrans('۰۱۲۳۴۵۶۷۸۹', '0123456789')
    return input_string.translate(persian_to_english)
Ai Download Python
def convert_persian_to_english(persian_string):
    # Dictionary to convert Persian to English numbers
    persian_to_english = {
        '۰': '0',
        '۱': '1',
        '۲': '2',
        '۳': '3',
        '۴': '4',
        '۵': '5',
        '۶': '6',
        '۷': '7',
        '۸': '8',
        '۹': '9'
    }
    
    # Convert Persian to English numbers
    english_string = ''.join(persian_to_english.get(char, char) for char in persian_string)
    
    return english_string
Sumy.amiri Download Python
def  Convert_Persian_numbers_to_English(txt):
    persian_engilsh = {
        '۰': '0',
        '۱': '1',
        '۲': '2',
        '۳': '3',
        '۴': '4',
        '۵': '5',
        '۶': '6',
        '۷': '7',
        '۸': '8',
        '۹': '9'
    }
    for i in txt:
        print(persian_engilsh.setdefault(i,i),end='')
def execution():
    txt = input()
    Convert_Persian_numbers_to_English(txt)
execution()
def convert_farsi_to_english(text):
    farsi_digits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
    english_digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    for farsi, english in zip(farsi_digits, english_digits):
        text = text.replace(farsi, english)
    return text

input_text = input("لطفاً رشته‌ای با اعداد فارسی وارد کنید: ")
output_text = convert_farsi_to_english(input_text)
print("رشته تبدیل شده:", output_text)
Roghaye.m Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close