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

بررسی کدپستی

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

تابعی بنویسید که کدپستی کاربر را به عنوان پارامتر دریافت کند و بررسی کند که کدپستی صحیح است یا خیر؟

کدپستی باید 15 رقم باشد
کدپستی فقط شامل اعداد است
🔥 14 ساعت قبل Amirdaneshfar جواب جدیدی برای این تمرین ارسال کرد
👨‍💻 11 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد
👨‍💻 14 ساعت قبل Amirdaneshfar این تمرین رو مشاهده کرد
👨‍💻 7 ساعت قبل User 10712 این تمرین رو مشاهده کرد

پاسخ‌ها 42

M = ("0123456789")
k = str(input("kod posti:  "))
r = k
if len(k)==15 :
    for i in k:
        x = M.find(i)
        if (x == -1) :
            print("false :kod posti az adad mibashad")
            break
    else:
        print("true")
else:
    print("false :tedad adad kod posti baead 15 ta bashe")
input_code = input("code posti: ")
def ceck(code):
    len_code = len(code)
    if len_code != 15 or code.isdigit() == False:
        return "False"
    return "True"
pr = ceck(input_code)
print(pr)

def check(code):
    try:
        int(code)  
    except ValueError:
        print("❌ Post code must be an integer.")
        return False

    if len(code) == 15:
        return True
    else:
        raise Exception("❌ Code is not standard (must be 15 digits).")

inp_code = input("Enter post code: ")

try:
    result = check(inp_code)
    print(result)
except Exception as e:
    print(e)

# Check the postal code
def postal_Code_Validation(postal_code):
    try:
        return len(postal_code) == 15 and postal_code.isdigit()
    except:
        return False


code = input("Please enter your zip code: ")
print(postal_Code_Validation(code))
def check_code(Codeposti):
    cleaned = ""
    for char in Codeposti:
        if char == " " or char.isalpha():
            continue
        cleaned += char

    a = len(cleaned)
    if a == 15:
        if cleaned.isdigit():
            print("✅ Your postal code is correct")
        else:
            print("❌ Your postal code must contain only digits.")
    else:
        print(f"❌ Your postal code must be 15 digits long. Currently it is {a} digits.")

try:
    Codeposti = input("Enter your number: ")
    check_code(Codeposti)
except Exception as e:
    print("❌ An error occurred:", str(e))

#گرفتن کدپستی از کاربر
def zipcode(code):
    #بررسی 15 کارکتری بودن کد پستی
    if len(code)==15:
        if code.isdigit(): 
            return True
    else: 
        return False
k=input('please enter the zip code here:')
print(zipcode(k))

ارسال جواب

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

×
بستن