Convert Persian to English numbers
Write a function that receives a string and converts Persian numbers into English numbers
Write a function that receives a string and converts Persian numbers into English numbers
let msg = 'error' alert(msg)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
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
def convert_persian_numbers_to_english(text): # Dictionary conversion to English numbers persian_to_english_numbers = { '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4', '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9' } # Replacement of any Persian number with corresponding English number converted_text = ''.join(persian_to_english_numbers.get(char, char) for char in text) return converted_text
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))
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
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)
def convert_to_english(text):
fa_nums = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]
en_nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
for i in range(len(fa_nums)):
text = text.replace(fa_nums[i], en_nums[i])
return text
def convert_to_persian(number): numbers_in_persian = { '1': '۱', '2': '۲', '3': '۳', '4': '۴', '5': '۵', '6': '۶', '7': '۷', '8': '۸', '9': '۹', '0': '۰' } # Convert number to string and translate each digit return ''.join(numbers_in_persian[digit] for digit in str(number)) try: num = input("Enter a number: ") if not num.isdigit(): raise ValueError("Please enter a valid number") persian_num = convert_to_persian(num) print(f"{num} => {persian_num}") except ValueError as e: print(f"Error: {e}")
Submitting answers is currently unavailable.
Write a program that receives a rectangular length and width from the input and prints its area in the output
We want to open a cow door, we don't know the safety password, but we have the following information: the second -digit safing password is the third digit, the last 4th of the person in the last one is smaller than their first digit ...
Write a function that receives the user's postcode as a parameter and checks whether the postcode is correct? Must be 15 digits?
Write a program that receives text from the input and prints the translation in the output. It can also be able to get English text from the entrance and convert it to a coder. Input: hooshang ....--- .... ...
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.