CP164 Lecture 5: Code for making a mirror in Python

76 views3 pages
School
Course

Document Summary

Mid = "m" def mirror(s): stack = stack() if len(s) == 0 or len(s) % 2 == 0: is_mirror = false else: if_mirror = true. #same as above if statement: is_mirror = (len(s) == 0 or len(s) % 2 == 0) i = 0. #put is_mirror in while so it returns false. #when there is a bad character while is_mirror and i < len(s) and s[i] != mid: if s[i] in chars: #push first half of s onto stack stack. push(s[i]) i += 1 else: #check if empty while is_mirror and i < len(s) and not stack. is_empty(): #added popped char to v v = stack. pop() #stack. pop() if v != s[i]: is_mirror = false else: i = i + 1. #if i < len(s): if not stack. is_empty():#same as above statement. #too many characters on left sie is_mirror = false elif i < len(s) and stack_is_empty(): #too many characters on the right side is_mirror = false return is_mirror.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions