Extraction of in -text numbers
Write a program that receives a text and extracts and prints the numbers inside.
For example:
Write a program that receives a text and extracts and prints the numbers inside.
For example:
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
import re def extract_numbers(text): """ این تابع اعداد موجود در متن را استخراج کرده و به صورت یک رشته برمیگرداند. """ # Use Regex to find all numbers in the text numbers = re.findall(r'\d+', text) # Combining the extracted numbers to a string return ''.join(numbers) # Get input from the user input_text = input("لطفاً یک متن وارد کنید: ") result = extract_numbers(input_text) # Printing results print("استخراج شده:", result)
Text = input("Enter your sentence:") numbers = [] for char in Text: if char.isdigit(): numbers.append(char) print(numbers)
text = input('enter text: ') for num in text: if num.isnumeric(): print(num,end='')
I wrote this form too :)
def numbers(t): num = [] for i in text: if i.isdigit(): num.append(i) return num text = input('input: ') print('output: ',numbers(text))
const str = "hooshang123hooshangi456"; const num = str.match(/\d{1,}/g); console.log(num);
#include <iostream> #include <string> #include<cctype> using namespace std; int main(){ int i; string a; cin>>a; for (i = 0 ; i < a.length() ; i++){ if (isdigit(a[i])){ cout<<a[i]; } } return 0; }
y = input("tex : ") x = "" for i in y : if i.isdigit(): x = x + i print(x)
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام 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.