+ 2

Paython Simple Metacharacters 1

Simple Metacharacters Write a program that takes a word as input, and outputs "Match" if the word has 4 letters, starts with "m" and ends with "e". The program should output "No match" if these mentioned requirements aren't satisfied. Sample Input mine Sample Output Match my code : s = input() words = ["mine","mile",] if s in words : print ("Match") else : print ("No match") if s in words : print("No match") and this show my all Test Case right without just one , where is the wrong and thank you

8th Oct 2021, 10:47 PM
Raoof Zakarna
8 Respuestas
+ 2
9th Oct 2021, 12:22 AM
Simon Sauter
Simon Sauter - avatar
+ 6
this is how i did it: import re word = input() #your code goes here pattern = r"^m..e
quot; if re.match(pattern, word): print("Match") else: print("No match")
13th Oct 2021, 5:14 PM
Sorin Sfechis
Sorin Sfechis - avatar
9th Oct 2021, 3:18 AM
Indira
Indira - avatar
+ 2
You need to use a regular expression to make sure your code works for every input matching the conditions. Take another look at lesson 84.1 of the Python Core course.
8th Oct 2021, 11:14 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Hi Raoof! There are too many words that start from "m" and end with "e" not just mile and mine. It's better to try using regex to solve this challenge since it's related to that lesson. Alternatively, you can approach this using string slicing method(first and last letters) or there are some in-built functions called startswith() and endswith(). You can use them to check the first letter and last letter. Syntax: var = "Raoof" print(var.startswith("R)) -> True print(var.endswith("F)) -> False
9th Oct 2021, 1:58 AM
Python Learner
Python Learner - avatar
0
I have look it 2 times but i dont understand yet
8th Oct 2021, 11:31 PM
Raoof Zakarna
0
i have problem to understand Simple Metacharacters 1 Regular expressions 1 Regular Expressions 3 i would to see if someone help me to skip that here and i can look in arabic to them
8th Oct 2021, 11:43 PM
Raoof Zakarna
- 1
import re w = input() p = r"^m..e
quot; if re.match(p, w): print("Match") else: print("No Match")
30th Jun 2022, 3:13 PM
Samwel Jomo