Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

تحديات برمجيةالتحدي الثالث - حل التمرين الخامس بلغة بايثون

المطلوب

قم بإنشاء برنامج يطلب من المستخدم إدخال نصّين, بعدها يقوم بطباعة ما إن كان النص الأول ينتهي بالنص الثاني أم لا.

مثال

Enter text 1: Welcome to my world
Enter text 2: world
--------------------------------
Text 1 is end with 'world'
	


الحل بلغة بايثون

text1 = input("Enter text 1: ")
text2 = input("Enter text 2: ")
text2_counter = 0
found = True
i = len(text1) - len(text2)
while i < len(text1) and found:
if text1[i] != text2[text2_counter]:
found = False
text2_counter += 1
i += 1
print('--------------------------------')
if found:
print("Text 1 end with '" + text2 + "'")
else:
print("Text 1 is not end with '" + text2 + "'")
text1 = input("Enter text 1: ") text2 = input("Enter text 2: ") text2_counter = 0 found = True i = len(text1) - len(text2) while i < len(text1) and found: if text1[i] != text2[text2_counter]: found = False text2_counter += 1 i += 1 print('--------------------------------') if found: print("Text 1 end with '" + text2 + "'") else: print("Text 1 is not end with '" + text2 + "'")

سنحصل على النتيجة التالية في حال تم إدخال نفس القيم التي تم تعليمها باللون الأصفر عند التشغيل.

Enter text 1: Welcome to my world
Enter text 2: world
--------------------------------
Text 1 is end with 'world'

الدورات

أدوات مساعدة

أقسام الموقع

دورات
مقالات كتب مشاريع أسئلة