Menu
CoddyTech
flag Ar iconالعربيةdown icon

عرض جهة اتصال

جزء من قسم المنطق وتدفّق التنفيذ في رحلة GDScript على Coddy. الدرس 26 من 78.

challenge icon

التحدي

سهل

تعامل مع الخيار 2 لعرض جهة اتصال واحدة. احتفظ بكل ما كتبته في الخطوات السابقة.

اكتب view_contact(contact_book: Dictionary). تقرأ الدالة اسمًا. إذا كان الاسم موجودًا في contact_book، تطبع التفاصيل الأربعة لجهة الاتصال بهذا التنسيق:

Name: Alice
Phone: 123-456-7890
Email: alice@example.com
Address: 123 Main St

وإلا، تطبع:

Contact not found!

في الحلقة، أضف فرع elif للخيار "2" يستدعي view_contact(contact_book)، قبل فرع "6". لا تطبع الدالة أي شيء آخر: لا نصًا للمطالبة بالإدخال.

جرّب بنفسك

extends Node

func _ready():
	var contact_book := {}

	while true:
		display_menu()
		var choice := OS.read_string_from_stdin()
		if choice == "1":
			add_contact(contact_book)
		elif choice == "6":
			break

func display_menu() -> void:
	print("Contact Book Menu:")
	print("1. Add Contact")
	print("2. View Contact")
	print("3. Edit Contact")
	print("4. Delete Contact")
	print("5. List All Contacts")
	print("6. Exit")

func add_contact(contact_book: Dictionary) -> void:
	var contact_name := OS.read_string_from_stdin()
	if contact_book.has(contact_name):
		print("Contact already exists!")
		return
	var phone := OS.read_string_from_stdin()
	var email := OS.read_string_from_stdin()
	var address := OS.read_string_from_stdin()
	contact_book[contact_name] = {"phone": phone, "email": email, "address": address}
	print("Contact added successfully!")

جميع دروس المنطق وتدفّق التنفيذ

تدرّب بنفسك: مترجم GDScript عبر الإنترنت