Notes
![]() ![]() Notes - notes.io |
# Define states
q0 = 0 # Start state
q1 = 1 # State after reading the first character
q_accept = 2 # Accepting state
q_reject = 3 # Rejecting state
# Initialize the current state to q0 (start state)
current_state = q0
# Check if the string length is exactly 2
if len(input_string) != 2:
return "Reject: String length is not 2"
# Define transitions
for char in input_string:
if current_state == q0:
# Transition from q0 to q1 on reading the first character
current_state = q1
elif current_state == q1:
# Transition from q1 to q_accept on reading the second character
current_state = q_accept
else:
# If we reach any state not defined in the transition
current_state = q_reject
break
# After processing the input string
if current_state == q_accept:
return "Accept: String is of length 2"
else:
return "Reject: Invalid input or incorrect string length"
# Test cases
print(validate_dfa("ab")) # Expected: Accept: String is of length 2
print(validate_dfa("abc")) # Expected: Reject: String length is not 2
print(validate_dfa("a")) # Expected: Reject: String length is not 2
print(validate_dfa("")) # Expected: Reject: String length is not 2
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team