צפייה באיש קשר
חלק מהיחידה לוגיקה וזרימת תוכנית במסלול ה-GDScript של Coddy. שיעור 26 מתוך 78.
אתגר
קלטפל בבחירה 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!")
כל השיעורים ביחידה לוגיקה וזרימת תוכנית
2קבלת החלטות מתקדמת
התאמה עם משתניםתנאי סף להתאמהתבניות מערכיםתבניות מילוניםבדיקות חברותסיכום – מנתח פקודות5אפליקציית ספר אנשי קשר
הצגת התפריטהוספת איש קשר8מנהל רשומות תלמידים
סקירת הפרויקטהוספת תלמידתרגלו בעצמכם: קומפיילר GDScript אונליין