حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

ویرایش شماره موبایل

تمرین آسان 1608 visibility link download flag

برنامه ایی بنویسید که از کاربر یک شماره موبایل دریافت شود، سپس:

اگر ابتدای آن +98 یا 98 است ، آن را به 0 تبدیل کند .
اگر داخل شماره از _ استفاده شده است ، آن را حذف کند.

درنهایت برای کاربر شماره موبایل ویرایش شده را چاپ کند

👨‍💻 15 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 17

a=input("Please,enter phone number:\n")
if a[0]=="9" and a[1]=="8":
    t1=a.replace(a[0],"0",1)
    c=t1.replace(t1[1],"",1)
    a=c
elif a[0]=="+" and a[1]=="9" and a[2]=="8":
    t1=a.replace(a[0],"0",1)  
    b=t1.replace(t1[1],"",1)
    c=b.replace(b[1],"",1)
    a=c
if a.find("_"):
    g=a.replace("_","")
    a=g
print(a)
phone_number=(input("enter you phone number with +98 or 98: "))
if phone_number.startswith("+98") or phone_number.startswith("98"):    phone_number=phone_number.replace("+","")    phone_number=phone_number.replace("98","0")
    phone_number=phone_number.replace("_","")
print(phone_number)

#include <iostream>
#include <cfloat> // برای فهمیدن ظرفیت متغیر ها :
#include <cctype> //  کاربرد های char
#include <vector>
#include <list>
#include <ctime>
#include <algorithm>

using namespace std ;

int main() {
    string number ;
    cout << "Enter mobile number = " ;
    cin >> number ;

    if (number.find("+98") == 0) {
        number.replace(0,3,"0") ;
    }
    else if (number.find("98") == 0) {
        number.replace(0,2,"0") ;
    }
    for(int i = 0 ; i < number.length() ; i++) {
        if (number[i] == '_') {
            number.erase(i,1) ;
        }
    }
    cout << number << endl;
    return 0;
}
no1 = str(input("enter phone no.: "))
#print(no1)
a = no1.replace("-","")
no2 = a[::-1]
#print(no2)
no3 = no2[0:10]
no4 = str(no3) + "0"
#print(no3)
#print(no4)
no5 = no4[::-1]
print(no5)

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن