Smart Contact Manager
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 76 of 78.
Challenge
MediumClean up a list of contacts. The program reads a whole number n, then n lines. Each line is a contact: a name, an email and a phone number, separated by commas (every line has exactly two commas).
Go through the contacts in order:
- Write the email in lowercase, and keep only the digits of the phone number:
(555) 123-4567becomes5551234567 - Skip the contact if the email is not valid: a valid email contains
@and., and no space - Skip the contact if the phone number does not have exactly
10digits - Skip the contact if a contact you kept before has the same email or the same phone number (after cleaning)
Print each contact you keep on its own line: the name, | , the email, | and the phone digits. Last, print Contacts kept: , how many you kept, of and n.
For these inputs:
3
John Doe,JOHN@email.com,123-456-7890
Jane Doe,jane@email.com,123.456.7890
Bob Smith,invalid.email,12345the output is:
John Doe | john@email.com | 1234567890
Contacts kept: 1 of 3Jane is skipped because her phone number has the same digits as John's, and Bob because his email has no @ and his phone number is too short.
Try it yourself
extends Node
func _ready():
var n := int(OS.read_string_from_stdin())
# Read n contacts, clean them and print the ones you keep
pass
All lessons in Logic & Flow
1Strings In Depth
String MethodsSearching in StringsReplace and TrimSplit and JoinRecap - Username Check4Dictionaries Part 2
Nested DictionariesArrays of DictionariesMerging DictionariesCopying DictionariesRecap - Frequency Counter2Advanced Decision Making
Match With VariablesMatch GuardsArray PatternsDictionary PatternsMembership ChecksRecap - Command Parser5Contact Book Application
Display MenuAdd Contact8Student Records Manager
Project OverviewAdd Student3Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysJagged ArraysCommon 2D Array PatternsRecap - Game Board6Sets with Dictionaries
What is a Set?Dictionary as a SetAdding and RemovingUnion and IntersectionSet DifferenceRecap - Remove Duplicates9Advanced Data Aggregation
Summing ValuesFinding Minimum and MaximumCustom SortingRecap - Dictionary SorterPractice on your own: Online GDScript compiler