Super excited to join this course!!! I have been wanting to learn python for quite some time and until now, I kind of did it, on and off. Most of the reason I discontinued my Py learning was due to the process of understanding the 'world' of Py through different types of character i.e numeric, integer, string and others, whereas what I interested the most in coding is the logic. The Code in Place starts with exactly what I want, a robot named Karel, a beeper, 4 basic commands (move, turn_left, pick_beeper, put_beeper) and 20 conditions that I can play with when creating loops and conditions.
Thursday, April 22, 2021
Code in Place 2021
I have done all my obligatory assignments, but still struggling in solving "the Fence Post Problem" when trying to solve the hospital assignment as a bonus point.
So here is my code:
def main():
"""
A code to build a hospital using 6 beepers and stop without creating a bug. Haven't succeeded yet :(
"""
if beepers_present():
buildhospital()
while front_is_clear():
findbeep()
buildhospital()
else:
while front_is_clear():
findbeep()
buildhospital()
def buildhospital():
turn_left()
move()
put_beeper()
move()
put_beeper()
turn_right()
move()
put_beeper() #4,3 second tower
turn_right()
move()
put_beeper() #4,2 second beeper second tower
move()
put_beeper()
turn_left()
def findbeep():
move()
while no_beepers_present():
move()
def turn_right():
for i in range(3):
turn_left()
if __name__ == '__main__':
run_karel_program('HospitalKarel2.w')
While my code works perfectly in a world where the last beeper of a hospital has a space before a wall (Fig 2 below), my code breaks when it has no space (Fig 3). What a bugger!
Subscribe to:
Post Comments (Atom)
Untuk Papa
Papa … Kini senyum itu tak bisa lagi kulihat Kebaikan itu tak bisa lagi kudapat Tapi jasa papa tetap melekat Hangat itu tetap mendekap ...
No comments:
Post a Comment