Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- # Python 3.7 #########################
- cmd = input("Enter a command, or just press enter to quit: \n> ")
- while cmd:
- match = re.match(r"Alexa, play ((\w+\s)*\w+)\.", cmd)
- if match:
- song_name = match.group(1)
- print(f"Playing {song_name}...")
- else:
- match = re.match(r"Alexa, dim the lights in ((\w+\s)*\w+)\.", cmd)
- if match:
- room_name = match.group(1)
- print(f"Dimming the lights in {room_name}...")
- else:
- match = re.match(r"Alexa, call ((\w+\s)*\w+)\.", cmd)
- if match:
- name = match.group(1)
- print(f"Calling {name}...")
- else:
- print(f"I don't understand.")
- cmd = input("Enter a command, or just press enter to quit: \n> ")
- # Python 3.8 #########################
- while cmd := input("Enter a command, or just press enter to quit: \n> "):
- if match := re.match(r"Alexa, play ((\w+\s)*\w+)\.", cmd):
- song_name = match.group(1)
- print(f"Playing {song_name}...")
- elif match := re.match(r"Alexa, dim the lights in ((\w+\s)*\w+)\.", cmd):
- room_name = match.group(1)
- print(f"Dimming the lights in {room_name}...")
- elif match := re.match(r"Alexa, call ((\w+\s)*\w+)\.", cmd):
- name = match.group(1)
- print(f"Calling {name}...")
- else:
- print(f"I don't understand.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement