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_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}")
def replace_numbre(): """ این تابع اعداد فارسی را به اعداد انگلیسی تبدیل میکند """ persian_numbers = "۱۲۳۴۵۶۷۸۹۰" english_numbers = "1234567890" conversion_fa = str.maketrans(persian_numbers,english_numbers) # The character's replacement method in a string result = "۱۳۸۳محمد متولد".translate(conversion_fa) return result print(replace_numbre())
Submitting answers is currently unavailable.
Write a program that receives a number from the input and checks whether the number is segmented to 5. Tips: The numeric is on 5 segments that remain the remaining 5 zero
Write a program that receives users' student names and number and stores in a file called Students.txt. Also, after each storage, display the entire information of this file at the output.
Write a program that receives the user's username and password and checks whether the username and password entered are correct? Username - Passwordamirhossein - 12345hooshang - 009922 ...
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام 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.