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

تشخیص شماره موبایل ایرانی

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

برنامه ای بنویسید که شماره موبایلی را از کاربر دریافت کند و در خروجی مشخص کند که آیا این شماره موبایل ایرانی است یا خیر.

پاسخ‌ها 16

شماره ای که وارد می شود باید با کد کشور باشد . (country calling code)

a = input("shomare mobile ra vared konid : ")
b = a.find("+98")
if b==-1 :
 print('in shomare irani nist')
else :
 print('shomare irani ast')
print('** lotfan hengham neveshtan shomare ba <<+98>>> bdon fasele edame shomare ra benevisid')
print('mesal: +98945***3264')
number=input('shomare: ')

if len(number)==11 and number[0:2]=='09':
    print('irani_ast')
elif len(number)==13 and number[0:4]=='+989':
    print('irani_ast')
else:
    print('irani_nist')

number = input("Enter your number: ")

if number.startswith("09") and len(number) == 11:
    print("Number is valid and  from Iran.")
elif number.startswith("+989") and len(number) == 13:
    print("Number is valid and  from Iran.")
else:
    print("Invalid number!")
phone_number = input("Enter a phone number please: ").replace(" ", "").strip()
if phone_number[0:2] == "09" and len(phone_number) == 11 :
    print("This is an Iranian phone number.")
elif phone_number[0:3] == "+98" and len(phone_number) == 13 and phone_number[3] == "9"  :
    print("Iranian.")
elif phone_number[0:4] == "0098" and len(phone_number) == 15  and phone_number[4] == "9" :
    print("Iranian.")
else :
    print("Not Iranian!")

import java.util.regex.Pattern

fun isIranianMobile(number: String): Boolean {
    val pattern = "^(?:\\+98|98|0)?9\\d{9}$"
    val compiledPattern = Pattern.compile(pattern)
    return compiledPattern.matcher(number).matches()
}
پاسخ هوش مصنوعی Ai Kotlin
phone = input("شماره موبایل را وارد کنید: ").strip().replace(" ", "").replace("-", "")
# بررسی ساده شماره موبایل ایرانی
if (len(phone) == 11 and phone.startswith('09') and phone[2:].isdigit()) or \
   (len(phone) == 10 and phone.startswith('9') and phone[1:].isdigit()):
    print("✅ شماره معتبر است")
else:
    print("❌ شماره معتبر نیست")

ارسال جواب

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

×
بستن