From a7ab662e3880b6c3f00d7ea00917671fee4c061a Mon Sep 17 00:00:00 2001 From: malikyilmaz <77412187+malikyilmaz@users.noreply.github.com> Date: Sat, 27 Mar 2021 02:02:23 +0100 Subject: [PATCH] Week7 --- Question 1.py | 20 ++++++++++++++++++++ Question 2.py | 35 +++++++++++++++++++++++++++++++++++ Question 3.py | 19 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 Question 1.py create mode 100644 Question 2.py create mode 100644 Question 3.py diff --git a/Question 1.py b/Question 1.py new file mode 100644 index 0000000..5f305af --- /dev/null +++ b/Question 1.py @@ -0,0 +1,20 @@ +""" +Write a program that detects the ID number hidden in a text. +We know that the format of the ID number is 2 letters, 1 digit, 2 letters, 2 digits, 1 letter, 1 digit (For example: AA4ZA11B1). +Input : AABZA1111AEGTV5YH678MK4FM53B6 +Output : MK4FM53B6 +Input : AEGTV5VZ4PF94B6YH678 +Output : VZ4PF94B6 +""" +import re + +def detect_ID(text): + pattern = r"\w\w\d\w\w\d\d\w\d" + for match in re.findall(pattern, text): + return match + + +text1 = "AABZA1111AEGTV5YH678MK4FM53B6" +text2 = "AEGTV5VZ4PF94B6YH678" +print( "Searched Text is : {}\nDetected ID is : {}".format(text1,detect_ID(text1))) +print(f"Searched Text is : {text2} \nDetected ID is : {detect_ID(text2)}") \ No newline at end of file diff --git a/Question 2.py b/Question 2.py new file mode 100644 index 0000000..c19bcdb --- /dev/null +++ b/Question 2.py @@ -0,0 +1,35 @@ +""" +Find words that are 8 letter long on this text ; + +Without, the night was cold and wet, but in the small parlour of Laburnum villa the blinds were drawn and the fire burned brightly. +Father and son were at chess; the former, +who possessed ideas about the game involving radical chances, +putting his king into such sharp and unnecessary perils that it even provoked comment from the white-haired old lady +knitting placidly by the fire. +"Hark at the wind," said Mr. White, "who, having seen a fatal mistake after it was too late, +was amiably desirous of preventing his son from seeing it. I'm listening, +" said the latter grimly surveying the board as he stretched out his hand. +"Check." I should hardly think that he's come tonight," said his father, with his hand poised over the board. +"Mate," replied the son. "That's the worst of living so far out," balled Mr. White with sudden and unlooked-for violence; +"Of all the beastly, slushy, out of the way places to live in, this is the worst. Path's a bog, and the road's a torrent. +I don't know what people are thinking about. I suppose because only two houses in the road are let, they think it doesn't matter." +""" +import re + +def detect_words(text): + pattern = r"\s\w{8}\s" + return re.findall(pattern, text) + +text = """Without, the night was cold and wet, but in the small parlour of Laburnum villa the blinds were +drawn and the fire burned brightly. Father and son were at chess; the former, who possessed ideas +about the game involving radical chances, putting his king into such sharp and unnecessary perils +that it even provoked comment from the white-haired old lady knitting placidly by the fire. +"Hark at the wind," said Mr. White, "who, having seen a fatal mistake after it was too late, was " \ + "amiably desirous of preventing his son from seeing it. I'm listening," said the latter grimly surveying the + board as he stretched out his hand. "Check." I should hardly think that he's come tonight," said his father, + with his hand poised over the board. "Mate," replied the son. "That's the worst of living so far out," balled Mr. " + "White with sudden and unlooked-for violence; "Of all the beastly, slushy, out of the way places to live in, +this is the worst. Path's a bog, and the road's a torrent. I don't know what people are thinking about. ' \ +'I suppose because only two houses in the road are let, they think it doesn't matter.""" + +print( "8 letters long words in the text are : {}".format(detect_words(text))) diff --git a/Question 3.py b/Question 3.py new file mode 100644 index 0000000..fb6cf38 --- /dev/null +++ b/Question 3.py @@ -0,0 +1,19 @@ +""" +Write a program that list according to email addresses without email domains in a text. +Input: The advencements in biomarine studies franky@google.com +with the investments necessary and Davos sinatra123@yahoo.com. +Then New Yorker article on wind farms... + +Output : franky sinatra123 +""" +import re + + +def detect_email(text): + pattern = "(\w+)@" + return re.findall(pattern, text) + +text = "The advencements in biomarine studies franky@google.com with the investments necessary and " \ + "Davos sinatra123@yahoo.com. Then New Yorker article on wind farms..." + +print( "Email addresses without email domains in the text : {}".format(detect_email(text)))