labNo float64 1 10 ⌀ | taskNo float64 0 4 ⌀ | questioner stringclasses 2 values | question stringlengths 9 201 | code stringlengths 18 30.3k | startLine float64 0 192 ⌀ | endLine float64 0 196 ⌀ | questionType stringclasses 4 values | answer stringlengths 2 905 | src stringclasses 3 values | code_processed stringlengths 12 28.3k ⌀ | id stringlengths 2 5 ⌀ | raw_code stringlengths 20 30.3k ⌀ | raw_comment stringlengths 10 242 ⌀ | comment stringlengths 9 207 ⌀ | q_code stringlengths 66 30.3k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | 2 | TA | What is the unit of x in sin(x) in task3? | import math
sin = math.sin
pi = math.pi
k = int(input('How many steps? '))
for i in range(k):
x = float(i) / (k-1) * 2 * pi
print (sin(x))
| 9 | 9 | variable | Radians | cs1qa | null | null | null | null | null | Question:
What is the unit of x in sin(x) in task3?
Code:
import math
sin = math.sin
pi = math.pi
k = int(input('How many steps? '))
for i in range(k):
x = float(i) / (k-1) * 2 * pi
print (sin(x))
|
2 | 2 | TA | Why do you need the if-else statement in lines 28-31 of Task 3? | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
# load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def jump_one_hurdle():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
def turn_right():
for i in range(3):
my_robot.turn_left()
while not my_robot.on_beeper():
if my_robot.front_is_clear():
my_robot.move()
else:
jump_one_hurdle() | 27 | 30 | reasoning | If the front of the robot is empty, proceed until the hurdles come out, and if the front is blocked, you have to cross the hurdles. | cs1qa | null | null | null | null | null | Question:
Why do you need the if-else statement in lines 28-31 of Task 3?
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
# load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def jump_one_hurdle():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
def turn_right():
for i in range(3):
my_robot.turn_left()
while not my_robot.on_beeper():
if my_robot.front_is_clear():
my_robot.move()
else:
jump_one_hurdle() |
5 | 0 | TA | How did you use the global variable in task 1? | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here
global balance
balance+=money
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
if money<=balance:
balance-=money
return True
else :
return False
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
if process=='d':
money=input("How much do you want to deposit? ")
deposit(int(money))
print("You deposted "+money+" won")
elif process=='w':
money=input("How much do you want to withdraw? ")
print("You've withdraw "+money+" won")
if not withdrawal(int(money)):
print("But you only have "+str(balance)+" won")
elif process=='c':
print("Your current balance is "+str(balance)+" won")
elif process=='':
break
#################
bank()
| 0 | 28 | variable | The reason balance is used as a global variable is for easy access within both functions. | cs1qa | null | null | null | null | null | Question:
How did you use the global variable in task 1?
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here
global balance
balance+=money
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
if money<=balance:
balance-=money
return True
else :
return False
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
if process=='d':
money=input("How much do you want to deposit? ")
deposit(int(money))
print("You deposted "+money+" won")
elif process=='w':
money=input("How much do you want to withdraw? ")
print("You've withdraw "+money+" won")
if not withdrawal(int(money)):
print("But you only have "+str(balance)+" won")
elif process=='c':
print("Your current balance is "+str(balance)+" won")
elif process=='':
break
#################
bank()
|
5 | 1 | TA | Is that because I don't think I can access the ship and balls in show_animation?? | from cs1graphics import *
from time import sleep
def draw_animal():
# Implement this function.
sun = Circle(18, Point(430, 220))
sun.setFillColor('yellow')
sun.setDepth(30)
paper.add(sun)
flare = Circle(24, Point(430, 220))
flare.setFillColor('red')
flare.setDepth(40)
paper.add(flare)
body = Rectangle(28, 10, Point(430, 110))
body.setFillColor('skyBlue')
ship.add(body)
ball1 = Circle(8, Point(430, 130))
ball2 = Circle(8, Point(430, 90))
ball1.setFillColor('yellow')
ball2.setFillColor('yellow')
balls.add(ball1)
balls.add(ball2)
def show_animation():
# Implement this function.
delay = 1
for i in range(15):
ship.move(-10, 0)
balls.move(0,10)
sleep(delay)
ship.move(-10, 0)
balls.move(0,-10)
sleep(delay)
paper = Canvas()
paper.setBackgroundColor('white')
paper.setWidth(500)
paper.setHeight(300)
paper.setTitle('Space')
ship = Layer()
paper.add(ship)
ship.setDepth(10)
balls = Layer()
ship.add(balls)
draw_animal()
show_animation() | 51 | 56 | reasoning | Yes, yes, it seemed to be accessible only if the declaration was made globally outside. | cs1qa | null | null | null | null | null | Question:
Is that because I don't think I can access the ship and balls in show_animation??
Code:
from cs1graphics import *
from time import sleep
def draw_animal():
# Implement this function.
sun = Circle(18, Point(430, 220))
sun.setFillColor('yellow')
sun.setDepth(30)
paper.add(sun)
flare = Circle(24, Point(430, 220))
flare.setFillColor('red')
flare.setDepth(40)
paper.add(flare)
body = Rectangle(28, 10, Point(430, 110))
body.setFillColor('skyBlue')
ship.add(body)
ball1 = Circle(8, Point(430, 130))
ball2 = Circle(8, Point(430, 90))
ball1.setFillColor('yellow')
ball2.setFillColor('yellow')
balls.add(ball1)
balls.add(ball2)
def show_animation():
# Implement this function.
delay = 1
for i in range(15):
ship.move(-10, 0)
balls.move(0,10)
sleep(delay)
ship.move(-10, 0)
balls.move(0,-10)
sleep(delay)
paper = Canvas()
paper.setBackgroundColor('white')
paper.setWidth(500)
paper.setHeight(300)
paper.setTitle('Space')
ship = Layer()
paper.add(ship)
ship.setDepth(10)
balls = Layer()
ship.add(balls)
draw_animal()
show_animation() |
3 | 2 | TA | Please also briefly explain the reason why you should use the while statement, not the for statement loop, in the process of picking up the beeper. | from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_and_pick():
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
def move_max():
while hubo.front_is_clear():
move_and_pick()
def left():
hubo.turn_left()
move_and_pick()
hubo.turn_left()
def right():
turn_right()
move_and_pick()
turn_right()
def back():
for i in range(2):
hubo.turn_left()
if hubo.front_is_clear:
while hubo.front_is_clear():
move_max()
if hubo.left_is_clear():
left()
move_max()
if hubo.right_is_clear():
right()
else:
hubo.turn_left()
move_max()
hubo.turn_left()
if hubo.right_is_clear():
back()
move_max()
hubo.turn_left()
move_max()
hubo.turn_left()
while hubo.carries_beepers():
hubo.drop_beeper() | 12 | 13 | reasoning | When picking up a beeper, it is necessary to give a beeper until there is no beeper, so we used a while statement that repeats while satisfying the condition, not for repeating a certain number. | cs1qa | null | null | null | null | null | Question:
Please also briefly explain the reason why you should use the while statement, not the for statement loop, in the process of picking up the beeper.
Code:
from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_and_pick():
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
def move_max():
while hubo.front_is_clear():
move_and_pick()
def left():
hubo.turn_left()
move_and_pick()
hubo.turn_left()
def right():
turn_right()
move_and_pick()
turn_right()
def back():
for i in range(2):
hubo.turn_left()
if hubo.front_is_clear:
while hubo.front_is_clear():
move_max()
if hubo.left_is_clear():
left()
move_max()
if hubo.right_is_clear():
right()
else:
hubo.turn_left()
move_max()
hubo.turn_left()
if hubo.right_is_clear():
back()
move_max()
hubo.turn_left()
move_max()
hubo.turn_left()
while hubo.carries_beepers():
hubo.drop_beeper() |
3 | 1 | TA | Why did you use the starting function in task2?? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo= Robot()
hubo.set_trace('blue')
def north():
while not hubo.facing_north():
hubo.turn_left()
def starting():
north()
for i in range(2):
hubo.turn_left()
go()
hubo.turn_left()
def go():
while hubo.front_is_clear():
hubo.move()
def pick_all():
while hubo.on_beeper():
hubo.pick_beeper()
while hubo.front_is_clear():
pick_all()
hubo.move()
pick_all()
for i in range(2):
hubo.turn_left()
go()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
starting()
| 13 | 17 | reasoning | The process of discarding the beeper and returning to (1,1) was solved with one starting(), so I used it to make it more convenient. | cs1qa | null | null | null | null | null | Question:
Why did you use the starting function in task2??
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo= Robot()
hubo.set_trace('blue')
def north():
while not hubo.facing_north():
hubo.turn_left()
def starting():
north()
for i in range(2):
hubo.turn_left()
go()
hubo.turn_left()
def go():
while hubo.front_is_clear():
hubo.move()
def pick_all():
while hubo.on_beeper():
hubo.pick_beeper()
while hubo.front_is_clear():
pick_all()
hubo.move()
pick_all()
for i in range(2):
hubo.turn_left()
go()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
starting()
|
3 | 3 | TA | Could you please explain the algorithm and code how you implemented Task Rain? | from cs1robots import *
# Your code must work for both of the worlds below.
# load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo= Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('red')
def turn_right():
for i in range(3):
hubo.turn_left()
def turn_around():
for i in range(2):
hubo.turn_left()
def move_or_close():
turn_right()
if hubo.front_is_clear():
hubo.move()
if hubo.left_is_clear() and hubo.right_is_clear():
turn_around()
hubo.move()
hubo.drop_beeper()
turn_right()
hubo.move()
else:
while not hubo.front_is_clear():
hubo.turn_left()
hubo.move()
else :
while not hubo.front_is_clear():
hubo.turn_left()
hubo.move()
# Now close all the windows in the house!
hubo.move()
turn_right()
move_or_close()
while not hubo.on_beeper():
move_or_close()
hubo.pick_beeper()
turn_right()
| 15 | 46 | code_explain | First, I closed all the windows, then put the beeper at the start to stop again at the starting point and run it until it meets the beeper again.
Placing the beeper is to go one space forward, turn right, then go out one space and come back and release the beeper if left and right are empty
When I put a beeper without leaving one space here, I couldn't go down in the second test case and keep putting the beeper, so I wrote the code that way. | cs1qa | null | null | null | null | null | Question:
Could you please explain the algorithm and code how you implemented Task Rain?
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
# load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo= Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('red')
def turn_right():
for i in range(3):
hubo.turn_left()
def turn_around():
for i in range(2):
hubo.turn_left()
def move_or_close():
turn_right()
if hubo.front_is_clear():
hubo.move()
if hubo.left_is_clear() and hubo.right_is_clear():
turn_around()
hubo.move()
hubo.drop_beeper()
turn_right()
hubo.move()
else:
while not hubo.front_is_clear():
hubo.turn_left()
hubo.move()
else :
while not hubo.front_is_clear():
hubo.turn_left()
hubo.move()
# Now close all the windows in the house!
hubo.move()
turn_right()
move_or_close()
while not hubo.on_beeper():
move_or_close()
hubo.pick_beeper()
turn_right()
|
2 | 3 | TA | What does move_and_pick in Task 4 do? | from cs1robots import*
load_world('worlds/harvest4.wld')
hubo=Robot(beepers=1)
hubo.set_trace("blue")
def turn_right():
for i in range (3):
hubo.turn_left()
def move_and_pick():
hubo.move()
if hubo.on_beeper():
while hubo.on_beeper():
hubo.pick_beeper()
def harvesting():
for i in range(5):
move_and_pick()
hubo.turn_left()
move_and_pick()
hubo.turn_left()
for i in range(5):
move_and_pick()
def turn_twice():
turn_right()
move_and_pick()
turn_right()
move_and_pick()
for i in range(2):
harvesting()
turn_twice()
harvesting() | 8 | 12 | variable | Unlike task1, if there is a beeper, it uses a while statement to pick up the beeper until the beeper disappears in the corresponding place! | cs1qa | null | null | null | null | null | Question:
What does move_and_pick in Task 4 do?
Code:
from cs1robots import*
load_world('worlds/harvest4.wld')
hubo=Robot(beepers=1)
hubo.set_trace("blue")
def turn_right():
for i in range (3):
hubo.turn_left()
def move_and_pick():
hubo.move()
if hubo.on_beeper():
while hubo.on_beeper():
hubo.pick_beeper()
def harvesting():
for i in range(5):
move_and_pick()
hubo.turn_left()
move_and_pick()
hubo.turn_left()
for i in range(5):
move_and_pick()
def turn_twice():
turn_right()
move_and_pick()
turn_right()
move_and_pick()
for i in range(2):
harvesting()
turn_twice()
harvesting() |
3 | 2 | TA | Please also briefly explain the reason why you should use the while statement, not the for statement loop, in the process of picking up the beeper. | from cs1robots import *
# Your code must work with any of the world files below.
#load_world('worlds/trash3.wld')
load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace = ('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_pick():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
def original_pos():
while not hubo.facing_north():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
hubo.move()
hubo.turn_left()
while hubo.front_is_clear():
hubo.move()
hubo.turn_left()
def move_across():
while hubo.front_is_clear():
move_pick()
original_pos()
k=1
while True:
move_across()
if k % 2 == 1:
hubo.turn_left()
if not hubo.front_is_clear():
break
move_pick()
hubo.turn_left()
k=k+1
else:
turn_right()
if not hubo.front_is_clear():
break
move_pick()
turn_right()
k=k+1
original_pos()
while hubo.carries_beepers():
hubo.drop_beeper()
| 38 | 53 | reasoning | Since the number of beeper is different for each location, here we define move_pick by using while until the beeper disappears. | cs1qa | null | null | null | null | null | Question:
Please also briefly explain the reason why you should use the while statement, not the for statement loop, in the process of picking up the beeper.
Code:
from cs1robots import *
# Your code must work with any of the world files below.
#load_world('worlds/trash3.wld')
load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace = ('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_pick():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
def original_pos():
while not hubo.facing_north():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
hubo.move()
hubo.turn_left()
while hubo.front_is_clear():
hubo.move()
hubo.turn_left()
def move_across():
while hubo.front_is_clear():
move_pick()
original_pos()
k=1
while True:
move_across()
if k % 2 == 1:
hubo.turn_left()
if not hubo.front_is_clear():
break
move_pick()
hubo.turn_left()
k=k+1
else:
turn_right()
if not hubo.front_is_clear():
break
move_pick()
turn_right()
k=k+1
original_pos()
while hubo.carries_beepers():
hubo.drop_beeper()
|
3 | 1 | TA | How did you know when you didn't have a beeper? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
my_robot = Robot()
my_robot.set_trace("red")
def turn_right():
for i in range(3):
my_robot.turn_left()
def line():
while my_robot.front_is_clear():
my_robot.move()
while my_robot.on_beeper():
my_robot.pick_beeper()
def turn_around():
for i in range(2):
my_robot.turn_left()
line()
turn_around()
line()
turn_right()
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
turn_around()
my_robot.move()
my_robot.turn_left()
| 28 | 29 | code_explain | my_robot.carries_beepers()
To leave the beeper only when the stomach is true | cs1qa | null | null | null | null | null | Question:
How did you know when you didn't have a beeper?
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
my_robot = Robot()
my_robot.set_trace("red")
def turn_right():
for i in range(3):
my_robot.turn_left()
def line():
while my_robot.front_is_clear():
my_robot.move()
while my_robot.on_beeper():
my_robot.pick_beeper()
def turn_around():
for i in range(2):
my_robot.turn_left()
line()
turn_around()
line()
turn_right()
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
turn_around()
my_robot.move()
my_robot.turn_left()
|
1 | 4 | TA | Seeing that you created the harvest() function and called it several times at the end of the code, is there any reason you didn't use the for statement here? | from cs1robots import *
load_world('worlds/harvest2.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_next_beeper():
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
def harvest_one():
hubo.pick_beeper()
move_next_beeper()
def harvest(a):
for i in range(2):
for j in range(a):
harvest_one()
turn_right()
hubo.turn_left()
while not hubo.on_beeper():
hubo.move()
for i in range(5):
harvest_one()
turn_right()
harvest(5)
harvest(4)
harvest(3)
harvest(2)
harvest(1)
hubo.pick_beeper()
| 26 | 30 | reasoning | When I used the for statement, I couldn't use it because I didn't know how to change the number in (). | cs1qa | null | null | null | null | null | Question:
Seeing that you created the harvest() function and called it several times at the end of the code, is there any reason you didn't use the for statement here?
Code:
from cs1robots import *
load_world('worlds/harvest2.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def move_next_beeper():
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
def harvest_one():
hubo.pick_beeper()
move_next_beeper()
def harvest(a):
for i in range(2):
for j in range(a):
harvest_one()
turn_right()
hubo.turn_left()
while not hubo.on_beeper():
hubo.move()
for i in range(5):
harvest_one()
turn_right()
harvest(5)
harvest(4)
harvest(3)
harvest(2)
harvest(1)
hubo.pick_beeper()
|
3 | 3 | TA | So how do you recognize the initial location? | from cs1robots import *
# Your code must work for both of the worlds below.
# load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
def turn_right():
for i in range (3):
hubo.turn_left()
def onemove():
if hubo.front_is_clear():
hubo.move()
turn_right()
if not hubo.front_is_clear():
hubo.turn_left()
else:
hubo.turn_left()
hubo.move()
turn_right()
if hubo.front_is_clear():
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
else:
turn_right()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
hubo.turn_left()
hubo.move()
else:
hubo.turn_left()
while not hubo.facing_north():
hubo.turn_left()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.drop_beeper()
hubo.move()
while not hubo.on_beeper():
onemove()
hubo.pick_beeper()
hubo.turn_left()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
# Now close all the windows in the house! | 47 | 47 | code_explain | I programmed it using the function while not hubo.on_beeper() so that when I first started, I put the beeper and then turned around and stepped on the beeper to know that it was back in place! | cs1qa | null | null | null | null | null | Question:
So how do you recognize the initial location?
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
# load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
def turn_right():
for i in range (3):
hubo.turn_left()
def onemove():
if hubo.front_is_clear():
hubo.move()
turn_right()
if not hubo.front_is_clear():
hubo.turn_left()
else:
hubo.turn_left()
hubo.move()
turn_right()
if hubo.front_is_clear():
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
else:
turn_right()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
hubo.turn_left()
hubo.move()
else:
hubo.turn_left()
while not hubo.facing_north():
hubo.turn_left()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.drop_beeper()
hubo.move()
while not hubo.on_beeper():
onemove()
hubo.pick_beeper()
hubo.turn_left()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
# Now close all the windows in the house! |
1 | 0 | TA | Can you briefly explain turn_right? | from cs1robots import*
create_world()
hubo=Robot()
hubo.set_trace('pink')
def turn_right():
for j in range(3):
hubo.turn_left()
def go_straight():
for i in range(9):
hubo.move()
def moving():
hubo.turn_left()
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
for i in range(4):
moving()
hubo.turn_left()
hubo.move()
moving()
| 6 | 8 | variable | turn_right is a function that rotates to the right | cs1qa | null | null | null | null | null | Question:
Can you briefly explain turn_right?
Code:
from cs1robots import*
create_world()
hubo=Robot()
hubo.set_trace('pink')
def turn_right():
for j in range(3):
hubo.turn_left()
def go_straight():
for i in range(9):
hubo.move()
def moving():
hubo.turn_left()
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
for i in range(4):
moving()
hubo.turn_left()
hubo.move()
moving()
|
2 | 0 | TA | Please briefly explain how to pick up the beeper in step 1 along with the function name. | from cs1robots import*
load_world('worlds/harvest3.wld')
hubo=Robot(beepers=0)
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def uturn_left():
hubo.turn_left()
hubo.move()
hubo.turn_left()
def uturn_right():
turn_right()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
turn_right()
def cycle():
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
uturn_left()
for i in range (5):
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
uturn_right()
for i in range (3):
cycle() | 22 | 39 | code_explain | When going to the left, the while statement is used to move to the end, and when going to the right, the for statement is used to proceed 5 times. | cs1qa | null | null | null | null | null | Question:
Please briefly explain how to pick up the beeper in step 1 along with the function name.
Code:
from cs1robots import*
load_world('worlds/harvest3.wld')
hubo=Robot(beepers=0)
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def uturn_left():
hubo.turn_left()
hubo.move()
hubo.turn_left()
def uturn_right():
turn_right()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
turn_right()
def cycle():
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
uturn_left()
for i in range (5):
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
uturn_right()
for i in range (3):
cycle() |
1 | 4 | TA | There was a way to pick diagonally, but why would you let them pick beepers while walking vertically? | from cs1robots import*
load_world('worlds/harvest2.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest(x):
for i in range(x):
hubo.pick_beeper()
hubo.move()
hubo.move()
hubo.pick_beeper()
def up_right():
for i in range(2):
hubo.move()
turn_right()
def down_right():
for i in range(2):
hubo.move()
hubo.turn_left()
def right_up():
for i in range(2):
hubo.turn_left()
hubo.move()
def right_down():
for i in range(2):
turn_right()
hubo.move()
hubo.turn_left()
for i in range (6):
hubo.move()
hubo.pick_beeper()
up_right()
harvest(1)
down_right()
harvest(2)
up_right()
harvest(3)
down_right()
harvest(4)
up_right()
harvest(5)
right_up()
harvest(4)
right_down()
harvest(3)
right_up()
harvest(2)
right_down()
harvest(1)
right_up()
hubo.pick_beeper() | 0 | 54 | reasoning | because I counted the steps of robot walking diagonally and realize that they are the same as this method walking vertically | cs1qa | null | null | null | null | null | Question:
There was a way to pick diagonally, but why would you let them pick beepers while walking vertically?
Code:
from cs1robots import*
load_world('worlds/harvest2.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest(x):
for i in range(x):
hubo.pick_beeper()
hubo.move()
hubo.move()
hubo.pick_beeper()
def up_right():
for i in range(2):
hubo.move()
turn_right()
def down_right():
for i in range(2):
hubo.move()
hubo.turn_left()
def right_up():
for i in range(2):
hubo.turn_left()
hubo.move()
def right_down():
for i in range(2):
turn_right()
hubo.move()
hubo.turn_left()
for i in range (6):
hubo.move()
hubo.pick_beeper()
up_right()
harvest(1)
down_right()
harvest(2)
up_right()
harvest(3)
down_right()
harvest(4)
up_right()
harvest(5)
right_up()
harvest(4)
right_down()
harvest(3)
right_up()
harvest(2)
right_down()
harvest(1)
right_up()
hubo.pick_beeper() |
4 | 0 | TA | Please tell me the name of the function you are adding in Task1! | from cs1robots import *
cnt=0
def go(a):
for i in range(a):
slave.move()
def turn(a):
for i in range(a):
slave.turn_left()
def pick_all():
global cnt
while(slave.on_beeper()):
slave.pick_beeper()
cnt+=1
def drop_all():
global cnt
for i in range(cnt):
slave.drop_beeper()
cnt=0
def add():
if(slave.on_beeper):
pick_all()
turn(3)
go(1)
drop_all()
turn(2)
go(1)
turn(3)
def over_ten():
global cnt
pick_all()
if(cnt>=10):
for i in range(cnt%10):
slave.drop_beeper()
go(1)
for i in range(cnt//10):
slave.drop_beeper()
else:
drop_all()
go(1)
cnt=0
#load_world('worlds/add1.wld')
#load_world('worlds/add2.wld')
load_world('worlds/add34.wld')
slave = Robot()
#slave.set_trace('blue')
turn(1)
go(1)
turn(3)
for i in range(10):
add()
if(slave.front_is_clear()):
go(1)
turn(3)
go(1)
turn(3)
while(slave.on_beeper()):
over_ten() | 34 | 46 | variable | First, number 1 is over_ten, which simply sums up the numbers above and below and then implements decimal rounding that needs to be executed. | cs1qa | null | null | null | null | null | Question:
Please tell me the name of the function you are adding in Task1!
Code:
from cs1robots import *
cnt=0
def go(a):
for i in range(a):
slave.move()
def turn(a):
for i in range(a):
slave.turn_left()
def pick_all():
global cnt
while(slave.on_beeper()):
slave.pick_beeper()
cnt+=1
def drop_all():
global cnt
for i in range(cnt):
slave.drop_beeper()
cnt=0
def add():
if(slave.on_beeper):
pick_all()
turn(3)
go(1)
drop_all()
turn(2)
go(1)
turn(3)
def over_ten():
global cnt
pick_all()
if(cnt>=10):
for i in range(cnt%10):
slave.drop_beeper()
go(1)
for i in range(cnt//10):
slave.drop_beeper()
else:
drop_all()
go(1)
cnt=0
#load_world('worlds/add1.wld')
#load_world('worlds/add2.wld')
load_world('worlds/add34.wld')
slave = Robot()
#slave.set_trace('blue')
turn(1)
go(1)
turn(3)
for i in range(10):
add()
if(slave.front_is_clear()):
go(1)
turn(3)
go(1)
turn(3)
while(slave.on_beeper()):
over_ten() |
2 | 2 | TA | Please briefly explain the code | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
#load_world('worlds/hurdles1.wld')
#load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() | 17 | 30 | code_explain | Task 3 created a function over one hurdle and crossed the hurdle whenever the front was blocked. | cs1qa | null | null | null | null | null | Question:
Please briefly explain the code
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
#load_world('worlds/hurdles1.wld')
#load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() |
6 | 2 | TA | Lastly, please explain the is_valid function created in task 3. | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
random.shuffle(cards)
global correct_list
correct_list=list(range(24))
print_cards()
correct_list=[]
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 == num2:
return False
if num1 in correct_list or num2 in correct_list:
return False
if num1 >23 and num2 >23:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if cards[num1][1]==cards[num2][1]:
return True
else:
correct_list.pop(-2)
correct_list.pop(-1)
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<=22: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
tries = tries+1 | 65 | 78 | variable | is_valid returns true if it doesn't hit the constraint, so if not true, it doesn't take continue. | cs1qa | null | null | null | null | null | Question:
Lastly, please explain the is_valid function created in task 3.
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
random.shuffle(cards)
global correct_list
correct_list=list(range(24))
print_cards()
correct_list=[]
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 == num2:
return False
if num1 in correct_list or num2 in correct_list:
return False
if num1 >23 and num2 >23:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if cards[num1][1]==cards[num2][1]:
return True
else:
correct_list.pop(-2)
correct_list.pop(-1)
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<=22: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
tries = tries+1 |
3 | 1 | TA | Which part of task2 puts down all beepers? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('blue')
def back():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
else:
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
back()
while hubo.front_is_clear():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
back()
hubo.move()
hubo.turn_left() | 23 | 24 | code_explain | In lines 24 and 25, while holding the beeper, we used a while statement to put down everything. | cs1qa | null | null | null | null | null | Question:
Which part of task2 puts down all beepers?
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('blue')
def back():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
else:
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
back()
while hubo.front_is_clear():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
back()
hubo.move()
hubo.turn_left() |
5 | 0 | TA | Task 1. Please explain the role of the Withdrawal function. | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
global balance
balance+=money
print("You deposited",money,"won")
return
#################
### implement ###
#################
# Do something on here !
pass
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance < money:
print("You've withdrawn", money, "won")
print("But you only have" ,balance, "won")
else:
balance-=money
print("You've withdrawn",money,"won")
return
#################
### implement ###
#################
# Do something on here !
pass
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Ouutput
while 1:
t = input("Deposit(d) or withdrawal(w)or balance check(c)??")
if t=='c':
print("Your current balance is",balance,"won")
if t=='w':
m = int(input("How much do you want to withdraw?"))
withdrawal(m)
elif t=='d':
m= int(input("How much do you want to deposit?"))
deposit(m)
elif t=='':
return
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
| 17 | 29 | variable | The withdrawal function is a function that withdraws money from the balance. When the balance is low, it informs that the money cannot be withdrawn, and when the balance is sufficient, the money is withdrawn. | cs1qa | null | null | null | null | null | Question:
Task 1. Please explain the role of the Withdrawal function.
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
global balance
balance+=money
print("You deposited",money,"won")
return
#################
### implement ###
#################
# Do something on here !
pass
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance < money:
print("You've withdrawn", money, "won")
print("But you only have" ,balance, "won")
else:
balance-=money
print("You've withdrawn",money,"won")
return
#################
### implement ###
#################
# Do something on here !
pass
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Ouutput
while 1:
t = input("Deposit(d) or withdrawal(w)or balance check(c)??")
if t=='c':
print("Your current balance is",balance,"won")
if t=='w':
m = int(input("How much do you want to withdraw?"))
withdrawal(m)
elif t=='d':
m= int(input("How much do you want to deposit?"))
deposit(m)
elif t=='':
return
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
|
6 | 2 | TA | Where is the first part of initializing cards, and what is the type of each element in the cards?? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list or i == num1 or i == num2: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def print_cards_initial():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if correct_list.count(num1) != 0 or correct_list.count(num2) != 0 or num1 == num2 or num1 < 0 or num2 < 0 or num1 > 23 or num2 > 23:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if cards[num1] == cards[num2]:
correct_list.append(num1)
correct_list.append(num2)
return True
num1 = None
num2 = None
print_cards()
return False
initialize()
print_cards_initial()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
if tries == 1:
print(str(tries) + "st try. You got " + str(len(correct_list)//2) + " pairs.")
if tries == 2:
print(str(tries) + "nd try. You got " + str(len(correct_list)//2) + " pairs.")
if tries == 3:
print(str(tries) + "rd try. You got " + str(len(correct_list)//2) + " pairs.")
if tries >= 4:
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
global num1
num1 = int(input("Enter the first number: "))
global num2
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
| 9 | 35 | variable | It seems that the first time cards are initialized in the initialize function, and the elements in cards are tuples. | cs1qa | null | null | null | null | null | Question:
Where is the first part of initializing cards, and what is the type of each element in the cards??
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list or i == num1 or i == num2: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def print_cards_initial():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if correct_list.count(num1) != 0 or correct_list.count(num2) != 0 or num1 == num2 or num1 < 0 or num2 < 0 or num1 > 23 or num2 > 23:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if cards[num1] == cards[num2]:
correct_list.append(num1)
correct_list.append(num2)
return True
num1 = None
num2 = None
print_cards()
return False
initialize()
print_cards_initial()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
if tries == 1:
print(str(tries) + "st try. You got " + str(len(correct_list)//2) + " pairs.")
if tries == 2:
print(str(tries) + "nd try. You got " + str(len(correct_list)//2) + " pairs.")
if tries == 3:
print(str(tries) + "rd try. You got " + str(len(correct_list)//2) + " pairs.")
if tries >= 4:
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
global num1
num1 = int(input("Enter the first number: "))
global num2
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
|
6 | 2 | student | ```
print_cards()
```
Is this the code you are visualizing? | from cs1graphics import *
import time
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = [Dohoo, Jeongmin, Jinyeong, Minsuk, Sanjae, Sungeun]
num_pads = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i%2 == 0: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 and num2 in correct_list:
elif num1 == num2:
elif not num1, num2 in num_pads:
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if num1 == num2:
correct_list.append(num1, num2)
else:
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
| 89 | 89 | code_understanding | Yes, it is | cs1qa | null | null | null | null | null | Question:
```
print_cards()
```
Is this the code you are visualizing?
Code:
from cs1graphics import *
import time
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = [Dohoo, Jeongmin, Jinyeong, Minsuk, Sanjae, Sungeun]
num_pads = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i%2 == 0: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 and num2 in correct_list:
elif num1 == num2:
elif not num1, num2 in num_pads:
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if num1 == num2:
correct_list.append(num1, num2)
else:
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
|
2 | 0 | TA | Additionally, please explain the reason for using beepers=36. | from cs1robots import *
load_world('worlds/harvest3.wld')
def move(n=1):
for i in range(n):
h.move()
def left():
h.turn_left()
def right():
for i in range(3):
left()
h = Robot(beepers=36)
h.set_trace('blue')
move()
def oneStep():
if h.on_beeper():
h.pick_beeper()
move()
def oneLine(flag):
for i in range(5):
oneStep()
if h.on_beeper():
h.pick_beeper()
if flag % 2 == 0:
left()
move()
left()
else:
right()
move()
right()
for i in range(6):
oneLine(i) | 11 | 13 | reasoning | And in case 2, there are 36 possible cases in the map, so I used 36. | cs1qa | null | null | null | null | null | Question:
Additionally, please explain the reason for using beepers=36.
Code:
from cs1robots import *
load_world('worlds/harvest3.wld')
def move(n=1):
for i in range(n):
h.move()
def left():
h.turn_left()
def right():
for i in range(3):
left()
h = Robot(beepers=36)
h.set_trace('blue')
move()
def oneStep():
if h.on_beeper():
h.pick_beeper()
move()
def oneLine(flag):
for i in range(5):
oneStep()
if h.on_beeper():
h.pick_beeper()
if flag % 2 == 0:
left()
move()
left()
else:
right()
move()
right()
for i in range(6):
oneLine(i) |
3 | 3 | TA | Please explain about task4. | from cs1robots import *
# Your code must work for both of the worlds below.
#load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
my_robot = Robot(beepers=100, avenue=2, street=6, orientation='E')
# Now close all the windows in the house!
def turn_right():
for a in range(3):
my_robot.turn_left()
def turn_around():
for b in range(2):
my_robot.turn_left()
my_robot.set_trace("blue")
my_robot.move()
turn_right()
my_robot.move()
while my_robot.get_pos()[0]!=3 or my_robot.get_pos()[1]!=6:
if my_robot.right_is_clear():
turn_right()
my_robot.move()
if my_robot.right_is_clear():
turn_around()
my_robot.move()
my_robot.drop_beeper()
turn_right()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
turn_right() | 20 | 46 | code_explain | All windows are clear on the right side of my_robot, but when the right side is clear, it may be due to the shape of the house as in the example in the video, so I thought that it should be distinguished.
So, if the right side is clear, I tried to move it to the right first.
If the right side was cleared by the shape of the house, the right side would not be cleared when moved to the right (then it will no longer be the shape of the house).
So, until the location of my_robot comes to (3,6), repeat the while statement
If the right side of my_robot is empty, move it to the right as described above and check whether the right side is clear. If it is clear, it is a window, so return to its original position and move with the beeper. If it is not clear, it is due to the shape of the house.
In other cases, if the front is clear, go straight, otherwise it is a wall, so I rotated to the left to move. | cs1qa | null | null | null | null | null | Question:
Please explain about task4.
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
#load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
my_robot = Robot(beepers=100, avenue=2, street=6, orientation='E')
# Now close all the windows in the house!
def turn_right():
for a in range(3):
my_robot.turn_left()
def turn_around():
for b in range(2):
my_robot.turn_left()
my_robot.set_trace("blue")
my_robot.move()
turn_right()
my_robot.move()
while my_robot.get_pos()[0]!=3 or my_robot.get_pos()[1]!=6:
if my_robot.right_is_clear():
turn_right()
my_robot.move()
if my_robot.right_is_clear():
turn_around()
my_robot.move()
my_robot.drop_beeper()
turn_right()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
turn_right() |
5 | 1 | student | Are geometry objects like tiger and sq_n also variables? | from cs1graphics import *
from time import sleep
world=Canvas(1200,1000)
world.setBackgroundColor("light blue")
world.setTitle("CS101 LAB5 Animation")
def draw_animal():
global tiger
global sq1
global sq2
global sq3
global sq4
global sq5
tiger=Layer()
sq1=Rectangle(160,75, Point(-80,-100))
tiger.add(sq1)
sq2=Rectangle(20,120, Point(-40,-60))
tiger.add(sq2)
sq3=Rectangle(20,120, Point(-120,-60))
tiger.add(sq3)
sq4=Square(50, Point(-170,-150))
tiger.add(sq4)
sq5=Square(5, Point(-185,-160))
tiger.add(sq5)
tiger.moveTo(1000,900)
world.add(tiger)
sq1.setFillColor("white")
sq2.setFillColor("white")
sq3.setFillColor("white")
sq4.setFillColor("white")
sq5.setFillColor("black")
sq1.setDepth(3)
sq2.setDepth(4)
sq3.setDepth(4)
sq4.setDepth(2)
sq5.setDepth(1)
def show_animation():
global tiger
for i in range(100):
tiger.move(-10,0)
sq2.rotate(30)
sq3.rotate(30)
sleep(0.01)
sq2.rotate(-60)
sq3.rotate(-60)
sleep(0.01)
sq2.rotate(30)
sq3.rotate(30)
sleep(0.01)
draw_animal()
show_animation()
| 7 | 12 | code_understanding | Oh, it can be called a variable | cs1qa | null | null | null | null | null | Question:
Are geometry objects like tiger and sq_n also variables?
Code:
from cs1graphics import *
from time import sleep
world=Canvas(1200,1000)
world.setBackgroundColor("light blue")
world.setTitle("CS101 LAB5 Animation")
def draw_animal():
global tiger
global sq1
global sq2
global sq3
global sq4
global sq5
tiger=Layer()
sq1=Rectangle(160,75, Point(-80,-100))
tiger.add(sq1)
sq2=Rectangle(20,120, Point(-40,-60))
tiger.add(sq2)
sq3=Rectangle(20,120, Point(-120,-60))
tiger.add(sq3)
sq4=Square(50, Point(-170,-150))
tiger.add(sq4)
sq5=Square(5, Point(-185,-160))
tiger.add(sq5)
tiger.moveTo(1000,900)
world.add(tiger)
sq1.setFillColor("white")
sq2.setFillColor("white")
sq3.setFillColor("white")
sq4.setFillColor("white")
sq5.setFillColor("black")
sq1.setDepth(3)
sq2.setDepth(4)
sq3.setDepth(4)
sq4.setDepth(2)
sq5.setDepth(1)
def show_animation():
global tiger
for i in range(100):
tiger.move(-10,0)
sq2.rotate(30)
sq3.rotate(30)
sleep(0.01)
sq2.rotate(-60)
sq3.rotate(-60)
sleep(0.01)
sq2.rotate(30)
sq3.rotate(30)
sleep(0.01)
draw_animal()
show_animation()
|
8 | 0 | TA | What does the 7th line for line in g: in task1 mean? | from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
f=open(output_filename,'w')
for i in input_filenames:
g=open(i,'r')
for line in g:
f.write(line)
g.close()
f.close()
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') | 2 | 7 | variable | It means to write to f for every line in g.
g is one of the files in input_filenames | cs1qa | null | null | null | null | null | Question:
What does the 7th line for line in g: in task1 mean?
Code:
from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
f=open(output_filename,'w')
for i in input_filenames:
g=open(i,'r')
for line in g:
f.write(line)
g.close()
f.close()
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') |
4 | 1 | TA | Why do you float after receiving input like x=float(input()) on lines 3-5? | def is_triangle(a, b, c):
if(a+b<=c or b+c<=a or a+c<=b):
return False
else:
return True
x=float(input())
y=float(input())
z=float(input())
print(is_triangle(x,y,z)) | 5 | 7 | reasoning | input defaults to
Because it's a string
I thought I had to change it to a float in order to do the math | cs1qa | null | null | null | null | null | Question:
Why do you float after receiving input like x=float(input()) on lines 3-5?
Code:
def is_triangle(a, b, c):
if(a+b<=c or b+c<=a or a+c<=b):
return False
else:
return True
x=float(input())
y=float(input())
z=float(input())
print(is_triangle(x,y,z)) |
2 | 0 | TA | Here are selections
1) move()
2) on_beeper()
3) turn_left()
4) drop_beeper()
Which function did you use to check if there's any beeper at your location? | from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
hubo.turn_left()
hubo.turn_left()
hubo.turn_left()
def move_and_pick():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
else:
hubo.move()
def pick_right():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
else:
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
def pick_left():
if hubo.on_beeper():
hubo.pick_beeper()
turn_right()
hubo.move()
turn_right()
else:
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick()
pick_left()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick()
pick_left()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick() | null | null | variable | on_beeper | cs1qa | null | null | null | null | null | Question:
Here are selections
1) move()
2) on_beeper()
3) turn_left()
4) drop_beeper()
Which function did you use to check if there's any beeper at your location?
Code:
from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
hubo.turn_left()
hubo.turn_left()
hubo.turn_left()
def move_and_pick():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
else:
hubo.move()
def pick_right():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
else:
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
def pick_left():
if hubo.on_beeper():
hubo.pick_beeper()
turn_right()
hubo.move()
turn_right()
else:
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick()
pick_left()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick()
pick_left()
hubo.pick_beeper()
for i in range(5):
move_and_pick()
pick_right()
for i in range(5):
move_and_pick() |
2 | 2 | TA | Please explain each function in Task3 Hurdle | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() | 13 | 24 | variable | I set the turn_right() function to turn right and the jump_one_hurdle() function to go over one hurdle. | cs1qa | null | null | null | null | null | Question:
Please explain each function in Task3 Hurdle
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() |
8 | 0 | TA | How did you write the merge function in Task 1? | from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
# Implement here
o = open(output_filename,'a')
for a in input_filenames:
f = open(a,'r')
data = f.read()
o.write(data)
f.close()
o.close()
# ...
pass
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') | 3 | 15 | variable | By taking a file one by one from the list of input files, making the entire sentence read, and then adding it to the output file.
I wrote the code. | cs1qa | null | null | null | null | null | Question:
How did you write the merge function in Task 1?
Code:
from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
# Implement here
o = open(output_filename,'a')
for a in input_filenames:
f = open(a,'r')
data = f.read()
o.write(data)
f.close()
o.close()
# ...
pass
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') |
9 | 1 | TA | What does assert do in the Card class? | import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
class Card:
def __init__(self,suit,face,value,image,state):
assert face in face_names and suit in suit_names
self.face=face
self.suit=suit
self.value=value
self.image=image
self.state=state
def create_deck():
deck=[]
for suit in suit_names:
for face in face_names:
img_name=img_path+suit+'_'+face+'.png'
deck.append(Card(suit,face,value[face_names.index(face)],img_name,True))
random.shuffle(deck)
return deck
def hand_value(hand):
value=0
for i in hand:
value=value+i.value
return value
def card_string(card):
if card.face=='Ace':
return 'An '+card.face+' of '+card.suit
else:
return 'A '+card.face+' of '+card.suit
def ask_yesno(prompt):
while prompt!='y' and prompt!='n':
prompt=input("\nPlay another round? (y/n) ")
if prompt=='y':
return True
else:
return False
def draw_card(dealer,player):
depth = 100
x0,y0 = 100,100
x1,y1 = 100,300
bj_board.clear()
for i in player:
count_i=20*player.index(i)
j=Image(i.image)
j.moveTo(100+count_i,300)
j.setDepth(depth-count_i)
bj_board.add(j)
text1=Text('Your Total: '+str(hand_value(player)),12,None)
text1.moveTo(500,300)
text1.setFontColor('yellow')
bj_board.add(text1)
for k in dealer:
count_k=20*dealer.index(k)
if k==dealer[0]:
if k.state==False:
k.image='./images/Back.png'
else:
k.image=img_path+k.suit+'_'+k.face+'.png'
else:
pass
j=Image(k.image)
j.moveTo(100+count_k,100)
j.setDepth(depth-count_k)
bj_board.add(j)
if dealer[0].state==True:
text2=Text("The dealer's Total: "+str(hand_value(dealer)),12,None)
text2.moveTo(500,100)
text2.setFontColor('yellow')
bj_board.add(text2)
else:
pass
count_i=count_i+10
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
main()
| 16 | 16 | variable | assert checks whether the face_names list and the suit_names list contain faces and suits! | cs1qa | null | null | null | null | null | Question:
What does assert do in the Card class?
Code:
import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
class Card:
def __init__(self,suit,face,value,image,state):
assert face in face_names and suit in suit_names
self.face=face
self.suit=suit
self.value=value
self.image=image
self.state=state
def create_deck():
deck=[]
for suit in suit_names:
for face in face_names:
img_name=img_path+suit+'_'+face+'.png'
deck.append(Card(suit,face,value[face_names.index(face)],img_name,True))
random.shuffle(deck)
return deck
def hand_value(hand):
value=0
for i in hand:
value=value+i.value
return value
def card_string(card):
if card.face=='Ace':
return 'An '+card.face+' of '+card.suit
else:
return 'A '+card.face+' of '+card.suit
def ask_yesno(prompt):
while prompt!='y' and prompt!='n':
prompt=input("\nPlay another round? (y/n) ")
if prompt=='y':
return True
else:
return False
def draw_card(dealer,player):
depth = 100
x0,y0 = 100,100
x1,y1 = 100,300
bj_board.clear()
for i in player:
count_i=20*player.index(i)
j=Image(i.image)
j.moveTo(100+count_i,300)
j.setDepth(depth-count_i)
bj_board.add(j)
text1=Text('Your Total: '+str(hand_value(player)),12,None)
text1.moveTo(500,300)
text1.setFontColor('yellow')
bj_board.add(text1)
for k in dealer:
count_k=20*dealer.index(k)
if k==dealer[0]:
if k.state==False:
k.image='./images/Back.png'
else:
k.image=img_path+k.suit+'_'+k.face+'.png'
else:
pass
j=Image(k.image)
j.moveTo(100+count_k,100)
j.setDepth(depth-count_k)
bj_board.add(j)
if dealer[0].state==True:
text2=Text("The dealer's Total: "+str(hand_value(dealer)),12,None)
text2.moveTo(500,100)
text2.setFontColor('yellow')
bj_board.add(text2)
else:
pass
count_i=count_i+10
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
main()
|
9 | 1 | TA | please explain create_deck() function | import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
"""
Define the Card class
"""
class Card:
''' Black Jack cards'''
pass
def create_deck(number = 1):
"""
Create a list("deck") of all 52 cards, shuffle them and return the list.
The list 'deck' have to include Card objects
A Card is represented by a object with four attributes: the face, the suit, value, state, and the image object
First, Have to define class 'Card'
"""
deck=[]
for s in suit_names:
i=0
for f in face_names:
c=Card()
c.face=f
c.suit=s
c.value=value[i]
c.state=True
c.image=Image(img_path+s+'_'+f+'.png')
i=i+1
deck.append(c)
random.shuffle(deck)
return deck
def hand_value(hand):
"""
hand is a list including card objects
Compute the value of the cards in the list "hand"
"""
count=0
for i in range(len(hand)):
count=count+hand[i].value
return count
def card_string(card):
"""
Parameter "card" is a Card object
Return a nice string to represent a card
(sucn as "a King of Spades" or "an Ace of Diamonds")
"""
article='a '
if card.face=='Ace':
article='an '
return article + card.face+ ' of ' + card.suit
def ask_yesno(prompt):
"""
Display the text prompt and let's the user enter a string.
If the user enters "y", the function returns "True",
and if the user enters "n", the function returns "False".
If the user enters anything else, the function prints "I beg your pardon!", and asks again,
repreting this until the user has entered a correct string.
"""
while True:
user_input=input(prompt)
if user_input=='y':
return True
break
elif user_input=='n':
return False
break
else :
print('I beg your pardon')
continue
def draw_card(dealer,player):
"""
This funuction add the cards of dealer and player to canvas, bj_board.
If the state of each Card object is false, then you have to show the hidden card image(Back.png).
The dealer's first card is hidden state.
The parameter dealer and player are List objects including Card Objects.
The start position of dealer's card is (100,100).
The start position of player's card is (100,300).
You can use the following methods for positioning images and text:
Image() Object, Text() Object, moveTo() method, setDepth() method.
You should use help function -
help('cs1graphics.Image') -> about Image(), moveTo(), setDepth()
help('cs1graphics.Text') -> about Text(),moveTo(), setDepth()
"""
depth = 100
depth1 = 100
x0,y0 = 100,100
x1,y1 = 100,300
inc=20
bj_board.clear()
hidden_img=Image(img_path+'Back.png')
for i in range(len(dealer)):
if dealer[i].state==True:
dealer[i].image.moveTo(x0,y0)
dealer[i].image.setDepth(depth)
bj_board.add(dealer[i].image)
x0=x0+inc
depth=depth-10
else:
hidden_img.moveTo(x0,y0)
hidden_img.setDepth(depth)
bj_board.add(hidden_img)
x0=x0+inc
depth=depth-10
for i in range(len(player)):
if player[i].state==True:
player[i].image.moveTo(x1,y1)
player[i].image.setDepth(depth1)
bj_board.add(player[i].image)
x1=x1+inc
depth1=depth1-10
text = Text("Your Total:"+str(hand_value(player)), 18, Point(450, 300))
text.setFontColor('yellow')
bj_board.add(text)
if dealer[0].state==True:
text1 = Text("The dealer's Total:"+str(hand_value(dealer)), 18, Point(450, 100))
text1.setFontColor('yellow')
bj_board.add(text1)
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
#help('cs1graphics.Text')
main()
| 22 | 46 | variable | This function defines all attributes of Class card | cs1qa | null | null | null | null | null | Question:
please explain create_deck() function
Code:
import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
"""
Define the Card class
"""
class Card:
''' Black Jack cards'''
pass
def create_deck(number = 1):
"""
Create a list("deck") of all 52 cards, shuffle them and return the list.
The list 'deck' have to include Card objects
A Card is represented by a object with four attributes: the face, the suit, value, state, and the image object
First, Have to define class 'Card'
"""
deck=[]
for s in suit_names:
i=0
for f in face_names:
c=Card()
c.face=f
c.suit=s
c.value=value[i]
c.state=True
c.image=Image(img_path+s+'_'+f+'.png')
i=i+1
deck.append(c)
random.shuffle(deck)
return deck
def hand_value(hand):
"""
hand is a list including card objects
Compute the value of the cards in the list "hand"
"""
count=0
for i in range(len(hand)):
count=count+hand[i].value
return count
def card_string(card):
"""
Parameter "card" is a Card object
Return a nice string to represent a card
(sucn as "a King of Spades" or "an Ace of Diamonds")
"""
article='a '
if card.face=='Ace':
article='an '
return article + card.face+ ' of ' + card.suit
def ask_yesno(prompt):
"""
Display the text prompt and let's the user enter a string.
If the user enters "y", the function returns "True",
and if the user enters "n", the function returns "False".
If the user enters anything else, the function prints "I beg your pardon!", and asks again,
repreting this until the user has entered a correct string.
"""
while True:
user_input=input(prompt)
if user_input=='y':
return True
break
elif user_input=='n':
return False
break
else :
print('I beg your pardon')
continue
def draw_card(dealer,player):
"""
This funuction add the cards of dealer and player to canvas, bj_board.
If the state of each Card object is false, then you have to show the hidden card image(Back.png).
The dealer's first card is hidden state.
The parameter dealer and player are List objects including Card Objects.
The start position of dealer's card is (100,100).
The start position of player's card is (100,300).
You can use the following methods for positioning images and text:
Image() Object, Text() Object, moveTo() method, setDepth() method.
You should use help function -
help('cs1graphics.Image') -> about Image(), moveTo(), setDepth()
help('cs1graphics.Text') -> about Text(),moveTo(), setDepth()
"""
depth = 100
depth1 = 100
x0,y0 = 100,100
x1,y1 = 100,300
inc=20
bj_board.clear()
hidden_img=Image(img_path+'Back.png')
for i in range(len(dealer)):
if dealer[i].state==True:
dealer[i].image.moveTo(x0,y0)
dealer[i].image.setDepth(depth)
bj_board.add(dealer[i].image)
x0=x0+inc
depth=depth-10
else:
hidden_img.moveTo(x0,y0)
hidden_img.setDepth(depth)
bj_board.add(hidden_img)
x0=x0+inc
depth=depth-10
for i in range(len(player)):
if player[i].state==True:
player[i].image.moveTo(x1,y1)
player[i].image.setDepth(depth1)
bj_board.add(player[i].image)
x1=x1+inc
depth1=depth1-10
text = Text("Your Total:"+str(hand_value(player)), 18, Point(450, 300))
text.setFontColor('yellow')
bj_board.add(text)
if dealer[0].state==True:
text1 = Text("The dealer's Total:"+str(hand_value(dealer)), 18, Point(450, 100))
text1.setFontColor('yellow')
bj_board.add(text1)
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
#help('cs1graphics.Text')
main()
|
3 | 1 | TA | What is move_and_drop in Task 2? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
#load_world( "worlds/trash2.wld" )
my_robot=Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def turn_around():
for i in range(2):
my_robot.turn_left()
def move_and_pick():
my_robot.move()
if my_robot.on_beeper():
while my_robot.on_beeper():
my_robot.pick_beeper()
def move_and_drop():
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
for i in range(9):
move_and_pick()
turn_around()
for i in range(9):
my_robot.move()
turn_right()
move_and_drop()
turn_around()
my_robot.move()
my_robot.turn_left() | 22 | 25 | variable | This function moves the robot one space and drops all the beepers it has. | cs1qa | null | null | null | null | null | Question:
What is move_and_drop in Task 2?
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
#load_world( "worlds/trash2.wld" )
my_robot=Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def turn_around():
for i in range(2):
my_robot.turn_left()
def move_and_pick():
my_robot.move()
if my_robot.on_beeper():
while my_robot.on_beeper():
my_robot.pick_beeper()
def move_and_drop():
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
for i in range(9):
move_and_pick()
turn_around()
for i in range(9):
my_robot.move()
turn_right()
move_and_drop()
turn_around()
my_robot.move()
my_robot.turn_left() |
3 | 0 | TA | Please explain how you used the loop in #1 to solve the problem! | from cs1robots import *
create_world()
hubo = Robot(orientation = 'W',avenue = 9, street =5)
while not hubo.facing_north() :
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear () :
hubo.move()
hubo.turn_left()
while hubo.front_is_clear () :
hubo.move() | 3 | 10 | code_explain | In No. 1, the first loop was used to make the north face, and then it turned left and moved to the west end, and then turned left again, and the loop was used to move to the south end, that is, to the starting point. | cs1qa | null | null | null | null | null | Question:
Please explain how you used the loop in #1 to solve the problem!
Code:
from cs1robots import *
create_world()
hubo = Robot(orientation = 'W',avenue = 9, street =5)
while not hubo.facing_north() :
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear () :
hubo.move()
hubo.turn_left()
while hubo.front_is_clear () :
hubo.move() |
1 | 4 | TA | Is there a reason you did hubo.on_beeper() in each function in task5? | from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
def rightup():
hubo.move()
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
for i in range(3):
hubo.turn_left()
def leftup():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
def leftdown():
hubo.move()
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
for i in range(3):
hubo.turn_left()
def rightdown():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
for i in range(4):
hubo.move()
for i in range(6):
rightup()
hubo.turn_left()
hubo.turn_left()
for i in range(5):
leftup()
for i in range(5):
leftdown()
hubo.turn_left()
hubo.turn_left()
for i in range(4):
rightdown()
for i in range(4):
rightup()
hubo.turn_left()
hubo.turn_left()
for i in range(3):
leftup()
for i in range(3):
leftdown()
hubo.turn_left()
hubo.turn_left()
for i in range(2):
rightdown()
for i in range(2):
rightup()
hubo.turn_left()
hubo.turn_left()
leftup()
leftdown()
| 8 | 8 | reasoning | There is no reason to add hubo.on_beeper() to each function, and it seems that each function was created separately. | cs1qa | null | null | null | null | null | Question:
Is there a reason you did hubo.on_beeper() in each function in task5?
Code:
from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
def rightup():
hubo.move()
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
for i in range(3):
hubo.turn_left()
def leftup():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
def leftdown():
hubo.move()
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
for i in range(3):
hubo.turn_left()
def rightdown():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
for i in range(4):
hubo.move()
for i in range(6):
rightup()
hubo.turn_left()
hubo.turn_left()
for i in range(5):
leftup()
for i in range(5):
leftdown()
hubo.turn_left()
hubo.turn_left()
for i in range(4):
rightdown()
for i in range(4):
rightup()
hubo.turn_left()
hubo.turn_left()
for i in range(3):
leftup()
for i in range(3):
leftdown()
hubo.turn_left()
hubo.turn_left()
for i in range(2):
rightdown()
for i in range(2):
rightup()
hubo.turn_left()
hubo.turn_left()
leftup()
leftdown()
|
4 | 3 | TA | When getting character_count_per_line
What is the reason for using for loop? | import math
sin = math.sin
pi = math.pi
for i in range(41) :
x = float(i) / 40 * 2 * pi
character_count_per_line = 0 # Change this line to print out sine curve correctly.
for j in range(int(40*sin(x))+40):
character_count_per_line +=1
output_str = '#' * character_count_per_line
#print(character_count_per_line)
print (output_str) | 5 | 13 | reasoning | Uh yeah
I must have been crazy because it was morning | cs1qa | null | null | null | null | null | Question:
When getting character_count_per_line
What is the reason for using for loop?
Code:
import math
sin = math.sin
pi = math.pi
for i in range(41) :
x = float(i) / 40 * 2 * pi
character_count_per_line = 0 # Change this line to print out sine curve correctly.
for j in range(int(40*sin(x))+40):
character_count_per_line +=1
output_str = '#' * character_count_per_line
#print(character_count_per_line)
print (output_str) |
2 | 2 | TA | Please explain each function in Task3 Hurdle | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() | 13 | 24 | variable | I set the turn_right() function to turn right and the jump_one_hurdle() function to go over one hurdle. | cs1qa | null | null | null | null | null | Question:
Please explain each function in Task3 Hurdle
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
# load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def jump_one_hurdle():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
while not hubo.on_beeper():
if hubo.front_is_clear():
hubo.move()
else:
jump_one_hurdle() |
5 | 0 | TA | Please explain how the functions deposit and withdrawal work! | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here
global balance
balance+=money
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
if money<=balance:
balance-=money
return True
else :
return False
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
if process=='d':
money=input("How much do you want to deposit? ")
deposit(int(money))
print("You deposted "+money+" won")
elif process=='w':
money=input("How much do you want to withdraw? ")
print("You've withdraw "+money+" won")
if not withdrawal(int(money)):
print("But you only have "+str(balance)+" won")
elif process=='c':
print("Your current balance is "+str(balance)+" won")
elif process=='':
break
#################
bank()
| 2 | 31 | variable | The deposit and withdrawal functions add or subtract the amount to be deposited or withdrawn from the global variable balance. | cs1qa | null | null | null | null | null | Question:
Please explain how the functions deposit and withdrawal work!
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here
global balance
balance+=money
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
if money<=balance:
balance-=money
return True
else :
return False
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
if process=='d':
money=input("How much do you want to deposit? ")
deposit(int(money))
print("You deposted "+money+" won")
elif process=='w':
money=input("How much do you want to withdraw? ")
print("You've withdraw "+money+" won")
if not withdrawal(int(money)):
print("But you only have "+str(balance)+" won")
elif process=='c':
print("Your current balance is "+str(balance)+" won")
elif process=='':
break
#################
bank()
|
1 | 4 | TA | Please explain #5 | from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest_upside():
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
def harvest_downside():
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
turn_right
for i in range(5):
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
def harvest_twoline():
for i in range(5):
harvest_upside()
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
harvest_downside()
for i in range(4):
turn_right()
harvest_downside()
for i in range(2):
harvest_twoline()
turn_right()
hubo.move()
turn_right()
hubo. move()
hubo.pick_beeper()
harvest_twoline() | 23 | 48 | code_explain | First, go to the 6th and 2nd points
After harvesting, going one space to the left and one space to the right
After harvesting all the rows
At points 11 and 7
Go to point 11, 8
After going to the 10th and 8th points
Also, repeating the left and the bottom, we harvested the second row.
I repeated it 3 times. | cs1qa | null | null | null | null | null | Question:
Please explain #5
Code:
from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest_upside():
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
def harvest_downside():
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
turn_right
for i in range(5):
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
def harvest_twoline():
for i in range(5):
harvest_upside()
hubo.move()
hubo.turn_left()
hubo.move()
hubo.pick_beeper()
harvest_downside()
for i in range(4):
turn_right()
harvest_downside()
for i in range(2):
harvest_twoline()
turn_right()
hubo.move()
turn_right()
hubo. move()
hubo.pick_beeper()
harvest_twoline() |
6 | 1 | TA | Why did you put lines 26~27? | from random import randint
def drawing_integers(lb, ub, trials):
a = []
for i in range(trials):
b = randint(lb, ub)
a.append(b)
return a
def average_integers(num_list):
a = 0
for i in num_list:
a += i
return a/len(num_list)
def count_integers(num_list):
a = []
for i in num_list:
k = num_list.count(i)
for j in range(k):
num_list.remove(i)
a.append((i,k))
a.sort()
return a
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
| 25 | 26 | reasoning | When k number of same numbers are included, counting them as duplicates is (5,2), (5,1) | cs1qa | null | null | null | null | null | Question:
Why did you put lines 26~27?
Code:
from random import randint
def drawing_integers(lb, ub, trials):
a = []
for i in range(trials):
b = randint(lb, ub)
a.append(b)
return a
def average_integers(num_list):
a = 0
for i in num_list:
a += i
return a/len(num_list)
def count_integers(num_list):
a = []
for i in num_list:
k = num_list.count(i)
for j in range(k):
num_list.remove(i)
a.append((i,k))
a.sort()
return a
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
|
1 | 3 | TA | For task 4, please briefly explain the round function. | from cs1robots import *
import time
load_world('worlds/harvest1.wld')
hubo = Robot(beepers=25)
sleep_time = 0.2
def turn_right():
for i in range(3):
hubo.turn_left()
def pick():
if hubo.on_beeper():
time.sleep(sleep_time)
hubo.pick_beeper()
def round():
for i in range(5):
pick()
time.sleep(sleep_time)
hubo.move()
pick()
hubo.turn_left()
time.sleep(sleep_time)
hubo.move()
hubo.turn_left()
for i in range(5):
pick()
time.sleep(sleep_time)
hubo.move()
pick()
turn_right()
time.sleep(sleep_time)
hubo.move()
for i in range(2):
round()
time.sleep(sleep_time)
hubo.move()
turn_right()
round()
| 15 | 30 | variable | Since it is a 6x6 square, I set it to round to pick up a 2x6 rectangle beeper. | cs1qa | null | null | null | null | null | Question:
For task 4, please briefly explain the round function.
Code:
from cs1robots import *
import time
load_world('worlds/harvest1.wld')
hubo = Robot(beepers=25)
sleep_time = 0.2
def turn_right():
for i in range(3):
hubo.turn_left()
def pick():
if hubo.on_beeper():
time.sleep(sleep_time)
hubo.pick_beeper()
def round():
for i in range(5):
pick()
time.sleep(sleep_time)
hubo.move()
pick()
hubo.turn_left()
time.sleep(sleep_time)
hubo.move()
hubo.turn_left()
for i in range(5):
pick()
time.sleep(sleep_time)
hubo.move()
pick()
turn_right()
time.sleep(sleep_time)
hubo.move()
for i in range(2):
round()
time.sleep(sleep_time)
hubo.move()
turn_right()
round()
|
2 | 1 | TA | I'm going to check it now. Can you explain how you made it for each task in the meantime? | from cs1robots import *
load_world('worlds/harvest3.wld')
hubo=Robot(beepers=6)
hubo.set_trace("blue")
def plant():
if not hubo.on_beeper():
hubo.drop_beeper()
def st1():
for i in range(5):
hubo.move()
plant()
hubo.turn_left()
hubo.move()
plant()
hubo.turn_left()
for i in range(5):
hubo.move()
plant()
for i in range(3):
hubo.turn_left()
hubo.move()
plant()
for i in range(3):
hubo.turn_left()
hubo.move()
for i in range(2):
st1()
for i in range(5):
hubo.move()
plant()
hubo.turn_left()
hubo.move()
plant()
hubo.turn_left()
for i in range(5):
hubo.move()
plant() | 0 | 39 | code_explain | In task2, in the function of task1, if there is no beeper, only the function is changed to leave the beeper. | cs1qa | null | null | null | null | null | Question:
I'm going to check it now. Can you explain how you made it for each task in the meantime?
Code:
from cs1robots import *
load_world('worlds/harvest3.wld')
hubo=Robot(beepers=6)
hubo.set_trace("blue")
def plant():
if not hubo.on_beeper():
hubo.drop_beeper()
def st1():
for i in range(5):
hubo.move()
plant()
hubo.turn_left()
hubo.move()
plant()
hubo.turn_left()
for i in range(5):
hubo.move()
plant()
for i in range(3):
hubo.turn_left()
hubo.move()
plant()
for i in range(3):
hubo.turn_left()
hubo.move()
for i in range(2):
st1()
for i in range(5):
hubo.move()
plant()
hubo.turn_left()
hubo.move()
plant()
hubo.turn_left()
for i in range(5):
hubo.move()
plant() |
6 | 0 | TA | Fn.remove(Fn[-1]) from task1
Why should I do it? | def fibonacci(upper_bound):
Fn = [0, 1]
while Fn[-1] < upper_bound :
Fn.append(Fn[-1] + Fn[-2])
Fn.remove(Fn[-1])
return Fn
pass
print(fibonacci(1000))
| 4 | 4 | reasoning | This is because the last term in the list is the value of the smallest Fibonacci sequence over 1000, so I have to delete the last term to get it as desired in the problem. | cs1qa | null | null | null | null | null | Question:
Fn.remove(Fn[-1]) from task1
Why should I do it?
Code:
def fibonacci(upper_bound):
Fn = [0, 1]
while Fn[-1] < upper_bound :
Fn.append(Fn[-1] + Fn[-2])
Fn.remove(Fn[-1])
return Fn
pass
print(fibonacci(1000))
|
1 | 3 | TA | Please briefly explain the four functions starting with harvest_ in task 4 | from cs1robots import *
#create_world()
load_world('worlds/harvest1.wld')
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
hubo.turn_left()
hubo.turn_left()
hubo.turn_left()
def harvest():
hubo.pick_beeper()
hubo.move()
def harvest_way():
for i in range(5):
harvest()
def harvest_right():
harvest_way()
turn_right()
harvest()
turn_right()
def harvest_left():
harvest_way()
hubo.turn_left()
harvest()
hubo.turn_left()
hubo.move()
hubo.turn_left()
for i in range(2):
harvest_right()
harvest_left()
harvest_right()
harvest_way()
hubo.pick_beeper()
| 10 | 28 | variable | task4: The harvest function has a short travel length, so I created a function that can travel as long as possible. | cs1qa | null | null | null | null | null | Question:
Please briefly explain the four functions starting with harvest_ in task 4
Code:
from cs1robots import *
#create_world()
load_world('worlds/harvest1.wld')
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
hubo.turn_left()
hubo.turn_left()
hubo.turn_left()
def harvest():
hubo.pick_beeper()
hubo.move()
def harvest_way():
for i in range(5):
harvest()
def harvest_right():
harvest_way()
turn_right()
harvest()
turn_right()
def harvest_left():
harvest_way()
hubo.turn_left()
harvest()
hubo.turn_left()
hubo.move()
hubo.turn_left()
for i in range(2):
harvest_right()
harvest_left()
harvest_right()
harvest_way()
hubo.pick_beeper()
|
3 | 3 | TA | Please explain the drop_go function | from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain1.wld')
# load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
# Now close all the windows in the house!
def back():
for i in range(2):
hubo.turn_left()
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def drop_go():
if hubo.left_is_clear():
hubo.move()
if not hubo.left_is_clear():
back()
hubo.drop_beeper()
back()
else:
back()
turn_right()
hubo.move()
def left_clear():
if hubo.left_is_clear():
hubo.turn_left()
hubo.move()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
hubo.move()
hubo.drop_beeper()
hubo.move()
turn_right()
while not hubo.on_beeper():
hubo.move()
drop_go()
if not hubo.front_is_clear():
turn_right()
hubo.pick_beeper()
back()
hubo.pick_beeper()
hubo.pick_beeper()
turn_right()
| 18 | 28 | variable | This is a function that distinguishes between windows and non-windows. | cs1qa | null | null | null | null | null | Question:
Please explain the drop_go function
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain1.wld')
# load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
# Now close all the windows in the house!
def back():
for i in range(2):
hubo.turn_left()
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def drop_go():
if hubo.left_is_clear():
hubo.move()
if not hubo.left_is_clear():
back()
hubo.drop_beeper()
back()
else:
back()
turn_right()
hubo.move()
def left_clear():
if hubo.left_is_clear():
hubo.turn_left()
hubo.move()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
hubo.move()
hubo.drop_beeper()
hubo.move()
turn_right()
while not hubo.on_beeper():
hubo.move()
drop_go()
if not hubo.front_is_clear():
turn_right()
hubo.pick_beeper()
back()
hubo.pick_beeper()
hubo.pick_beeper()
turn_right()
|
8 | 1 | TA | H = True
year = 1722 #start from 1723
for line in f:
if H:
H = False
continue
I wonder why you use this H | f = open("average-latitude-longitude-countries.csv", "r")
#1, 2
# coolist = []
list1 = []
list2 = []
def slicer(l): #first ',' is index = 4
t = l.find("\"", 6) #fourth '\"'
a = t+1 #second ','
b = l.find(",", a+1) #third ','
return (a, b)
H = True
for line in f:
if H:
H = False #to avoid header
continue
l = line
a, b = slicer(l)
# coolist.append((l[1:3], l[6:a-1], float(l[a+1:b]), float(l[b+1:])))
#1
list1.append((l[1:3], l[6:a-1]))
list2.append((l[1:3], (float(l[a+1:b]), float(l[b+1:]))))
f.close()
#1 print
print(list1)
print(list2)
#2:
for i in list2:
if i[1][0] < 0:
for j in list1:
if j[0]==i[0]:
print(j[0])
#3
code = input("Enter country code: ")
for item in list1:
if code == item[0]:
print(item[1])
break | 13 | 17 | reasoning | To read the first line of the document and skip right away.
The for line in f: statement takes the first line of f and then exits with continue immediately. | cs1qa | null | null | null | null | null | Question:
H = True
year = 1722 #start from 1723
for line in f:
if H:
H = False
continue
I wonder why you use this H
Code:
f = open("average-latitude-longitude-countries.csv", "r")
#1, 2
# coolist = []
list1 = []
list2 = []
def slicer(l): #first ',' is index = 4
t = l.find("\"", 6) #fourth '\"'
a = t+1 #second ','
b = l.find(",", a+1) #third ','
return (a, b)
H = True
for line in f:
if H:
H = False #to avoid header
continue
l = line
a, b = slicer(l)
# coolist.append((l[1:3], l[6:a-1], float(l[a+1:b]), float(l[b+1:])))
#1
list1.append((l[1:3], l[6:a-1]))
list2.append((l[1:3], (float(l[a+1:b]), float(l[b+1:]))))
f.close()
#1 print
print(list1)
print(list2)
#2:
for i in list2:
if i[1][0] < 0:
for j in list1:
if j[0]==i[0]:
print(j[0])
#3
code = input("Enter country code: ")
for item in list1:
if code == item[0]:
print(item[1])
break |
5 | 0 | TA | And if it is an empty string, why can I use break instead of return? | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
global balance
balance=balance+money
print("You deposited %d won"%balance)
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
pass
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance<money:
print("You've withdrawn %d won"%money)
print("But you only have %d won"%balance)
return None
balance=balance-money
print("You've withdrawn %d won"%money)
#################
### implement ###
#################
# Do something on here !
pass
#################
def check():
global balance
print("Your current balance is %d won"%balance)
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='':
break
elif process== 'd':
money=input("How much do you want to deposit?")
deposit(int(money))
elif process== 'w':
money=input("How much do you want to withdraw?")
withdrawal(int(money))
elif process== 'c':
check()
else:
print("Please, press d or w or c or return")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
| 46 | 47 | reasoning | The purpose of using break was to end the function by ending the loop in the bank function, and since return is also to terminate the function and return a specific value, I thought that it can be used for the purpose of terminating the function. | cs1qa | null | null | null | null | null | Question:
And if it is an empty string, why can I use break instead of return?
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
global balance
balance=balance+money
print("You deposited %d won"%balance)
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
pass
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance<money:
print("You've withdrawn %d won"%money)
print("But you only have %d won"%balance)
return None
balance=balance-money
print("You've withdrawn %d won"%money)
#################
### implement ###
#################
# Do something on here !
pass
#################
def check():
global balance
print("Your current balance is %d won"%balance)
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='':
break
elif process== 'd':
money=input("How much do you want to deposit?")
deposit(int(money))
elif process== 'w':
money=input("How much do you want to withdraw?")
withdrawal(int(money))
elif process== 'c':
check()
else:
print("Please, press d or w or c or return")
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
|
4 | 0 | TA | How do you get the number of beepers when writing? | import cs1robots
def main():
cs1robots.load_world("worlds/add34.wld")
hubo = cs1robots.Robot(beepers=100)
def turn_right():
for _ in range(3):
hubo.turn_left()
return None
def back():
for _ in range(2):
hubo.turn_left()
return None
def get():
cnt = 0
while(hubo.on_beeper()):
cnt+=1
hubo.pick_beeper()
return cnt
def read():
sum = 0
while(True):
sum = 10 * sum + get()
if(not hubo.front_is_clear()):
break
hubo.move()
back()
while(hubo.front_is_clear()):
hubo.move()
return sum
def drop(cnt):
for _ in range(cnt):
hubo.drop_beeper()
def write(x):
while(hubo.front_is_clear()):
hubo.move()
back()
while(hubo.front_is_clear()):
drop(x%10)
x//=10
hubo.move()
x=read()
turn_right()
hubo.move()
turn_right()
y=read()
x += y
hubo.turn_left()
hubo.move()
hubo.turn_left()
write(x)
main() | 39 | 46 | code_explain | First, we moved the robot to the last column, then flipped the direction and moved forward, dividing the remainder of the number currently remaining in each column divided by 10, and then the remaining number divided by 10. | cs1qa | null | null | null | null | null | Question:
How do you get the number of beepers when writing?
Code:
import cs1robots
def main():
cs1robots.load_world("worlds/add34.wld")
hubo = cs1robots.Robot(beepers=100)
def turn_right():
for _ in range(3):
hubo.turn_left()
return None
def back():
for _ in range(2):
hubo.turn_left()
return None
def get():
cnt = 0
while(hubo.on_beeper()):
cnt+=1
hubo.pick_beeper()
return cnt
def read():
sum = 0
while(True):
sum = 10 * sum + get()
if(not hubo.front_is_clear()):
break
hubo.move()
back()
while(hubo.front_is_clear()):
hubo.move()
return sum
def drop(cnt):
for _ in range(cnt):
hubo.drop_beeper()
def write(x):
while(hubo.front_is_clear()):
hubo.move()
back()
while(hubo.front_is_clear()):
drop(x%10)
x//=10
hubo.move()
x=read()
turn_right()
hubo.move()
turn_right()
y=read()
x += y
hubo.turn_left()
hubo.move()
hubo.turn_left()
write(x)
main() |
8 | 0 | TA | What is the f.read() function in task1? | from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
temp_list = []
for name in input_filenames:
fin = open(name, 'rt')
temp_list.append(fin.read())
fin.close()
fout = open(output_filename, 'xt')
fout.write(''.join(temp_list))
fout.close()
return None
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') | 8 | 8 | variable | This function reads all the text in the file. | cs1qa | null | null | null | null | null | Question:
What is the f.read() function in task1?
Code:
from time import sleep
import elice_utils
def merge(input_filenames, output_filename):
temp_list = []
for name in input_filenames:
fin = open(name, 'rt')
temp_list.append(fin.read())
fin.close()
fout = open(output_filename, 'xt')
fout.write(''.join(temp_list))
fout.close()
return None
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') |
4 | 2 | TA | Please explain task3 | import math
sin = math.sin
pi = math.pi
n=input('How many steps? ')
n=int(n)
for i in range(n):
x = float(i) / (n-1) * 2 * pi
print (sin(x)) | 4 | 8 | code_explain | task3 changed the type of the value received as an input to int so that n can be used in the for statement. | cs1qa | null | null | null | null | null | Question:
Please explain task3
Code:
import math
sin = math.sin
pi = math.pi
n=input('How many steps? ')
n=int(n)
for i in range(n):
x = float(i) / (n-1) * 2 * pi
print (sin(x)) |
1 | 1 | TA | Please tell me what the jump() function does! | from cs1robots import *
load_world('worlds/hurdles1.wld')
hubo=Robot()
hubo.set_trace('blue')
def jump():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
hubo.move()
for i in range(4):
jump()
hubo.pick_beeper() | 6 | 14 | variable | Perform hurdle-over moves. | cs1qa | null | null | null | null | null | Question:
Please tell me what the jump() function does!
Code:
from cs1robots import *
load_world('worlds/hurdles1.wld')
hubo=Robot()
hubo.set_trace('blue')
def jump():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
turn_right()
hubo.move()
hubo.turn_left()
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
hubo.move()
for i in range(4):
jump()
hubo.pick_beeper() |
6 | 2 | TA | What is the reason for the condition of print_cards like that?? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if (correct_list.count(i)==1)or(tries==0): # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range
if (0<=num1)&(num1<=23)&(0<=num2)&(num2<=23)&(num1!=num2)&(correct_list.count(num1)==0)&(correct_list.count(num2)==0):
return True
# Return Boolean value according to the result.
###########################################################################
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
if cards[num1][1]==cards[num2][1]:
print_cards()
return True
print_cards()
correct_list.pop()
correct_list.pop()
print_cards()
return False
initialize()
print_cards()
tries += 1
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
| 39 | 59 | reasoning | This is to print only photos in correct_list. Also, if tries==0, it is to show photos temporarily after the game starts. | cs1qa | null | null | null | null | null | Question:
What is the reason for the condition of print_cards like that??
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if (correct_list.count(i)==1)or(tries==0): # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range
if (0<=num1)&(num1<=23)&(0<=num2)&(num2<=23)&(num1!=num2)&(correct_list.count(num1)==0)&(correct_list.count(num2)==0):
return True
# Return Boolean value according to the result.
###########################################################################
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
if cards[num1][1]==cards[num2][1]:
print_cards()
return True
print_cards()
correct_list.pop()
correct_list.pop()
print_cards()
return False
initialize()
print_cards()
tries += 1
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
|
3 | 1 | TA | Which part of task2 puts down all beepers? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('blue')
def back():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
else:
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
back()
while hubo.front_is_clear():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
back()
hubo.move()
hubo.turn_left() | 23 | 24 | code_explain | In lines 24 and 25, while holding the beeper, we used a while statement to put down everything. | cs1qa | null | null | null | null | null | Question:
Which part of task2 puts down all beepers?
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
# load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('blue')
def back():
hubo.turn_left()
hubo.turn_left()
while hubo.front_is_clear():
if hubo.on_beeper():
hubo.pick_beeper()
else:
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
back()
while hubo.front_is_clear():
hubo.move()
for i in range(3):
hubo.turn_left()
hubo.move()
while hubo.carries_beepers():
hubo.drop_beeper()
back()
hubo.move()
hubo.turn_left() |
6 | 2 | TA | What are the conditions for showing the card? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
start_time = time.time()
for i in range(len(num_pads)):
################################################################
if True: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h + h)
canvas.add(cards[i][0])
w = w+ 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(5)
w = 0
h = 0
for i in range(len(num_pads)):
canvas.remove(cards[i][0])
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 in correct_list or num2 in correct_list:
return False
elif num1 > 24 or num1 > 24 or num2 > 24 or num2 > 24:
return False
elif num1==num2:
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
w = 0
h = 0
i_w = 70
i_h = 90
canvas.add(cards[num1][0])
cards[num1][0].moveTo(i_w + 100 * (num1%6), i_h + 130 * (num1//6) )
canvas.add(cards[num2][0])
cards[num2][0].moveTo(i_w + 100 * (num2%6), i_h + 130 * (num2//6))
time.sleep(1)
if cards[num2][1]==cards[num1][1]:
correct_list.append(num1)
correct_list.append(num2)
return True
else:
canvas.remove(cards[num1][0])
canvas.remove(cards[num2][0])
return False
print_cards()
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while not len(correct_list)==24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong...")
tries += 1
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
| 73 | 123 | code_explain | In is valid, I checked whether the range of integer numbers is correct, whether the two numbers are different, etc., and by checking in the check function, I checked whether the name in the temp tuple of the card is the same. | cs1qa | null | null | null | null | null | Question:
What are the conditions for showing the card?
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
start_time = time.time()
for i in range(len(num_pads)):
################################################################
if True: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h + h)
canvas.add(cards[i][0])
w = w+ 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(5)
w = 0
h = 0
for i in range(len(num_pads)):
canvas.remove(cards[i][0])
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 in correct_list or num2 in correct_list:
return False
elif num1 > 24 or num1 > 24 or num2 > 24 or num2 > 24:
return False
elif num1==num2:
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
w = 0
h = 0
i_w = 70
i_h = 90
canvas.add(cards[num1][0])
cards[num1][0].moveTo(i_w + 100 * (num1%6), i_h + 130 * (num1//6) )
canvas.add(cards[num2][0])
cards[num2][0].moveTo(i_w + 100 * (num2%6), i_h + 130 * (num2//6))
time.sleep(1)
if cards[num2][1]==cards[num1][1]:
correct_list.append(num1)
correct_list.append(num2)
return True
else:
canvas.remove(cards[num1][0])
canvas.remove(cards[num2][0])
return False
print_cards()
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while not len(correct_list)==24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong...")
tries += 1
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
|
6 | 2 | TA | How did you implement showing all the pictures at the beginning | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
################################################################
random.shuffle(cards)
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if(num1 == num2 or num1 < 0 or num2 < 0 or num1 >= 24 or num2 >= 24 or num1 in correct_list or num2 in correct_list):
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if(cards[num1][1] != cards[num2][1]):
correct_list.pop()
correct_list.pop()
print_cards()
return False
else:
return True
return False
initialize()
for i in range(24):
correct_list.append(i)
print_cards()
for i in range(24):
correct_list.pop()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
tries += 1
| 97 | 100 | code_explain | Implemented in lines 99-104.
First, I appended 1 to 24 to the correct_list and then called print_cards to show the image.
Then, correct_list was cleared by doing correct_list.pop() 24 times.
Another call to print_cards was made to show only the numbers this time. | cs1qa | null | null | null | null | null | Question:
How did you implement showing all the pictures at the beginning
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
################################################################
random.shuffle(cards)
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if(num1 == num2 or num1 < 0 or num2 < 0 or num1 >= 24 or num2 >= 24 or num1 in correct_list or num2 in correct_list):
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if(cards[num1][1] != cards[num2][1]):
correct_list.pop()
correct_list.pop()
print_cards()
return False
else:
return True
return False
initialize()
for i in range(24):
correct_list.append(i)
print_cards()
for i in range(24):
correct_list.pop()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
tries += 1
|
3 | 3 | TA | Please explain about task4. | from cs1robots import *
# Your code must work for both of the worlds below.
#load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
my_robot = Robot(beepers=100, avenue=2, street=6, orientation='E')
# Now close all the windows in the house!
def turn_right():
for a in range(3):
my_robot.turn_left()
def turn_around():
for b in range(2):
my_robot.turn_left()
my_robot.set_trace("blue")
my_robot.move()
turn_right()
my_robot.move()
while my_robot.get_pos()[0]!=3 or my_robot.get_pos()[1]!=6:
if my_robot.right_is_clear():
turn_right()
my_robot.move()
if my_robot.right_is_clear():
turn_around()
my_robot.move()
my_robot.drop_beeper()
turn_right()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
turn_right() | 24 | 46 | code_explain | All windows are clear on the right side of my_robot, but when the right side is clear, it may be due to the shape of the house as in the example in the video, so I thought that it should be distinguished.
So, if the right side is clear, I tried to move it to the right first.
If the right side was cleared by the shape of the house, the right side would not be cleared when moved to the right (then it will no longer be the shape of the house).
So, until the location of my_robot comes to (3,6), repeat the while statement
If the right side of my_robot is empty, move it to the right as described above and check whether the right side is clear. If it is clear, it is a window, so return to its original position and move with the beeper. If it is not clear, it is due to the shape of the house.
In other cases, if the front is clear, go straight, otherwise it is a wall, so I rotated to the left to move. | cs1qa | null | null | null | null | null | Question:
Please explain about task4.
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
#load_world('worlds/rain1.wld')
load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
my_robot = Robot(beepers=100, avenue=2, street=6, orientation='E')
# Now close all the windows in the house!
def turn_right():
for a in range(3):
my_robot.turn_left()
def turn_around():
for b in range(2):
my_robot.turn_left()
my_robot.set_trace("blue")
my_robot.move()
turn_right()
my_robot.move()
while my_robot.get_pos()[0]!=3 or my_robot.get_pos()[1]!=6:
if my_robot.right_is_clear():
turn_right()
my_robot.move()
if my_robot.right_is_clear():
turn_around()
my_robot.move()
my_robot.drop_beeper()
turn_right()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
else:
if my_robot.front_is_clear():
my_robot.move()
else:
my_robot.turn_left()
my_robot.move()
turn_right() |
2 | 2 | TA | Please explain task3 haha | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
#load_world('worlds/hurdles1.wld')
#load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def jump_one_hurdle():
while my_robot.front_is_clear():
my_robot.move()
if not my_robot.on_beeper():
my_robot.turn_left()
my_robot.move()
for i in range(2):
turn_right()
my_robot.move()
my_robot.turn_left()
while not my_robot.on_beeper():
jump_one_hurdle()
# ... | 0 | 31 | code_explain | task3 programmed the robot to go forward at jump_on_hurdle until there are no obstacles in front, and over the obstacles while not on the beeper. | cs1qa | null | null | null | null | null | Question:
Please explain task3 haha
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
#load_world('worlds/hurdles1.wld')
#load_world('worlds/hurdles2.wld')
load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def jump_one_hurdle():
while my_robot.front_is_clear():
my_robot.move()
if not my_robot.on_beeper():
my_robot.turn_left()
my_robot.move()
for i in range(2):
turn_right()
my_robot.move()
my_robot.turn_left()
while not my_robot.on_beeper():
jump_one_hurdle()
# ... |
2 | 0 | TA | Is there a reason for dividing move1 and move2 in task1? | from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def move_and_pick():
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
def move1():
for i in range(5):
move_and_pick()
hubo.turn_left()
move_and_pick()
hubo.turn_left()
def move2():
for i in range(5):
move_and_pick()
turn_right()
move_and_pick()
turn_right()
move_and_pick()
for i in range(2):
move1()
move2()
move1()
for i in range(5):
move_and_pick() | 11 | 22 | reasoning | Because I tried to separate the two cases of turning left and turning right | cs1qa | null | null | null | null | null | Question:
Is there a reason for dividing move1 and move2 in task1?
Code:
from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot()
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def move_and_pick():
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
def move1():
for i in range(5):
move_and_pick()
hubo.turn_left()
move_and_pick()
hubo.turn_left()
def move2():
for i in range(5):
move_and_pick()
turn_right()
move_and_pick()
turn_right()
move_and_pick()
for i in range(2):
move1()
move2()
move1()
for i in range(5):
move_and_pick() |
3 | 3 | TA | Could you explain task 4's block function? | from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain2.wld')
#load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('red')
# Now close all the windows in the house!
def turn_right():
for i in range(3):
hubo.turn_left()
def block():
while(hubo.front_is_clear()):
hubo.move()
if(hubo.left_is_clear()):
hubo.turn_left()
hubo.move()
if(hubo.front_is_clear()):
hubo.drop_beeper()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
block()
turn_right()
block()
turn_right()
block()
turn_right()
block()
turn_right()
hubo.move()
hubo.turn_left()
block()
turn_right()
while(not hubo.on_beeper()):
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
| 14 | 21 | variable | I chose a clockwise rotation method, in which case the block is a function that makes the beeper drop when there is no wall (when the window is open) while going straight along one side (until it is blocked by the other side) | cs1qa | null | null | null | null | null | Question:
Could you explain task 4's block function?
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain2.wld')
#load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('red')
# Now close all the windows in the house!
def turn_right():
for i in range(3):
hubo.turn_left()
def block():
while(hubo.front_is_clear()):
hubo.move()
if(hubo.left_is_clear()):
hubo.turn_left()
hubo.move()
if(hubo.front_is_clear()):
hubo.drop_beeper()
hubo.move()
hubo.drop_beeper()
hubo.turn_left()
block()
turn_right()
block()
turn_right()
block()
turn_right()
block()
turn_right()
hubo.move()
hubo.turn_left()
block()
turn_right()
while(not hubo.on_beeper()):
hubo.move()
hubo.pick_beeper()
hubo.turn_left()
|
5 | 0 | TA | Why should I use global balance in task1? | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance+=money
print('You deposited', balance, 'won')
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance-=money
print('You\'ve withdraw', money, 'won')
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='':
break
elif process=='d':
money=int(input('How much do you want to deposit? '))
deposit(money)
elif process=='w':
money=int(input('How much do you want to withdraw? '))
if balance>money:
withdrawal(money)
else:
print('You\'ve withdrawn ', money, 'won')
print('But you only have', balance, 'won')
elif process=='c':
print('Your current balance is ', balance, 'won')
else:
print('Please, press d or w or c or return')
#################
bank()
| 12 | 12 | reasoning | It is because withdraw, deposit, and bank must be continuously used within the defined function, because at this time, the input value must be used. | cs1qa | null | null | null | null | null | Question:
Why should I use global balance in task1?
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance+=money
print('You deposited', balance, 'won')
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance-=money
print('You\'ve withdraw', money, 'won')
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='':
break
elif process=='d':
money=int(input('How much do you want to deposit? '))
deposit(money)
elif process=='w':
money=int(input('How much do you want to withdraw? '))
if balance>money:
withdrawal(money)
else:
print('You\'ve withdrawn ', money, 'won')
print('But you only have', balance, 'won')
elif process=='c':
print('Your current balance is ', balance, 'won')
else:
print('Please, press d or w or c or return')
#################
bank()
|
6 | 2 | TA | Why did you do num1-=1 and num2-=1 at the 138th and 139th? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
global num1
global num2
num1 = -1
num2 = -1
first = 0
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
random.shuffle(cards)
################################################################
# 3-2-1. shuffle the card list
################################################################
def print_cards():
# global num1
# global num2
global first
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
if first == 0:
for i in range(len(num_pads)):
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
w+=100
if w % 600 == 0:
w = 0
h += 130
time.sleep(2)
first += 1
canvas.clear()
w = 0
h = 0
for i in range(len(num_pads)):
################################################################
if i==num1 or i==num2 or i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
for i in range(len(correct_list)):
if correct_list[i]==num1 or correct_list[i]==num2:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if cards[num1][1] == cards[num2][1]:
correct_list.append(num1)
correct_list.append(num2)
return True
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)!=24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
# global num1
# global num2
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
num1 = -1
num2 = -1
print_cards()
tries+=1
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
| 69 | 140 | reasoning | The reason for substituting -1 for num1 and num2 was to print only the correct list when an incorrect answer was answered. | cs1qa | null | null | null | null | null | Question:
Why did you do num1-=1 and num2-=1 at the 138th and 139th?
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_list = []
global num1
global num2
num1 = -1
num2 = -1
first = 0
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
random.shuffle(cards)
################################################################
# 3-2-1. shuffle the card list
################################################################
def print_cards():
# global num1
# global num2
global first
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
if first == 0:
for i in range(len(num_pads)):
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
w+=100
if w % 600 == 0:
w = 0
h += 130
time.sleep(2)
first += 1
canvas.clear()
w = 0
h = 0
for i in range(len(num_pads)):
################################################################
if i==num1 or i==num2 or i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
for i in range(len(correct_list)):
if correct_list[i]==num1 or correct_list[i]==num2:
return False
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
print_cards()
if cards[num1][1] == cards[num2][1]:
correct_list.append(num1)
correct_list.append(num2)
return True
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)!=24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
# global num1
# global num2
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
num1 = -1
num2 = -1
print_cards()
tries+=1
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
###########################################################################
|
8 | 0 | TA | Then, please explain the algorithm you wrote in Task 1! | import elice_utils
from time import sleep
def merge(input_filenames, output_filename):
merge_result = open('output.txt', 'a')
for i in range(len(input_filenames)):
merge = open(input_filenames[i], 'r')
for line in merge:
data = line
merge_result.write(data)
pass
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') | 3 | 9 | code_explain | At number one, the input comes into the list
Read each list through iteration
After reading this for each line through the open function
I wrote it in the output | cs1qa | null | null | null | null | null | Question:
Then, please explain the algorithm you wrote in Task 1!
Code:
import elice_utils
from time import sleep
def merge(input_filenames, output_filename):
merge_result = open('output.txt', 'a')
for i in range(len(input_filenames)):
merge = open(input_filenames[i], 'r')
for line in merge:
data = line
merge_result.write(data)
pass
merge(['kaist1.txt', 'kaist2.txt', 'kaist3.txt'], 'output.txt')
sleep(0.5) # Wait 0.5 seconds before creating a download link.
elice_utils.send_file('output.txt') |
3 | 2 | TA | Why is it only turning right from line 45 until i<9? | from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace('blue')
hubo.set_pause(0.1)
turn_check = 1
def turn_right():
for i in range(3):
hubo.turn_left()
def go_straight():
while hubo.front_is_clear():
hubo.move()
def pick_and_move():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
def turn_left_left():
hubo.turn_left()
pick_and_move()
hubo.turn_left()
def turn_right_right():
turn_right()
pick_and_move()
turn_right()
def drop_all():
while hubo.carries_beepers():
hubo.drop_beeper()
for i in range(10):
while hubo.front_is_clear():
pick_and_move()
if turn_check:
turn_left_left()
turn_check = 0
elif i<9:
turn_right_right()
turn_check = 1
while hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
go_straight()
drop_all()
hubo.turn_left() | 44 | 46 | reasoning | If i <9, it was bent to the right at 10, 10 and an error occurred, so I handled it separately. | cs1qa | null | null | null | null | null | Question:
Why is it only turning right from line 45 until i<9?
Code:
from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
hubo = Robot()
hubo.set_trace('blue')
hubo.set_pause(0.1)
turn_check = 1
def turn_right():
for i in range(3):
hubo.turn_left()
def go_straight():
while hubo.front_is_clear():
hubo.move()
def pick_and_move():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
def turn_left_left():
hubo.turn_left()
pick_and_move()
hubo.turn_left()
def turn_right_right():
turn_right()
pick_and_move()
turn_right()
def drop_all():
while hubo.carries_beepers():
hubo.drop_beeper()
for i in range(10):
while hubo.front_is_clear():
pick_and_move()
if turn_check:
turn_left_left()
turn_check = 0
elif i<9:
turn_right_right()
turn_check = 1
while hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
go_straight()
drop_all()
hubo.turn_left() |
3 | 2 | TA | In task 3, tell us the role of the st function. | from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
my_robot=Robot()
my_robot.set_trace('red')
def st():
while(my_robot.front_is_clear()):
my_robot.move()
while(my_robot.on_beeper()):
my_robot.pick_beeper()
def turn_right():
for i in range(3):
my_robot.turn_left()
def zig():
st()
my_robot.turn_left()
my_robot.move()
my_robot.turn_left()
if my_robot.on_beeper():
my_robot.pick_beeper()
st()
turn_right()
if not my_robot.front_is_clear():
return
my_robot.move()
turn_right()
if my_robot.on_beeper():
my_robot.pick_beeper()
for i in range(5):
zig()
for i in range(2):
my_robot.turn_left()
st()
my_robot.turn_left()
| 9 | 13 | variable | It is a function to go straight until an obstacle comes in front of you, but if there is a beeper, it is a function to pick up everything. | cs1qa | null | null | null | null | null | Question:
In task 3, tell us the role of the st function.
Code:
from cs1robots import *
# Your code must work with any of the world files below.
load_world('worlds/trash3.wld')
# load_world('worlds/trash4.wld')
my_robot=Robot()
my_robot.set_trace('red')
def st():
while(my_robot.front_is_clear()):
my_robot.move()
while(my_robot.on_beeper()):
my_robot.pick_beeper()
def turn_right():
for i in range(3):
my_robot.turn_left()
def zig():
st()
my_robot.turn_left()
my_robot.move()
my_robot.turn_left()
if my_robot.on_beeper():
my_robot.pick_beeper()
st()
turn_right()
if not my_robot.front_is_clear():
return
my_robot.move()
turn_right()
if my_robot.on_beeper():
my_robot.pick_beeper()
for i in range(5):
zig()
for i in range(2):
my_robot.turn_left()
st()
my_robot.turn_left()
|
6 | 0 | TA | Why did you float(upper_bound) in task1? | def fibonacci(upper_bound):
pass
A=[0,1]
C = True
while A[-1] < float(upper_bound):
a= A[-1]+A[-2]
A.append(a)
A.pop()
return A
print(fibonacci(1000))
| 0 | 4 | reasoning | When writing the code, I think I used a float because I thought it was a string because I was confused with the input function. | cs1qa | null | null | null | null | null | Question:
Why did you float(upper_bound) in task1?
Code:
def fibonacci(upper_bound):
pass
A=[0,1]
C = True
while A[-1] < float(upper_bound):
a= A[-1]+A[-2]
A.append(a)
A.pop()
return A
print(fibonacci(1000))
|
9 | 0 | TA | You created two tasks by using a class.
So, what do you think is the advantage of class? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
class Card:
pass
def initialize():
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
random.shuffle(cards)
def convert():
for i in range(24):
img = cards[i][0]
name = cards[i][1]
cards[i] = Card()
cards[i].img = img
cards[i].name = name
cards[i].correct = False
def print_cards(num=[]):
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
if i in num:
cards[i].img.moveTo(i_w + w, i_h+h)
canvas.add(cards[i].img)
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
if (cards[num1].correct) or (cards[num2].correct):
return False
if num1==num2:
return False
if not (num1>=0 and num1<24 and num2>=0 and num2<24):
return False
return True
def check(num1, num2):
l=[]
for i in range(24):
if cards[i].correct:
l.append(i)
print_cards([num1, num2]+l)
if cards[num1].name==cards[num2].name:
cards[num1].correct = True
cards[num2].correct = True
return True
else:
print_cards(l)
return False
initialize()
convert()
print_cards(list(range(len(num_pads))))
print_cards()
print("### Welcome to the Python Memento game!!! ###")
l=[]
for i in range(24):
if cards[i].correct:
l.append(i)
while len(l)<24:
print(str(tries) + "th try. You got " + str(len(l)//2) + " pairs.")
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
tries+=1
| null | null | reasoning | I think the advantage of being able to access the corresponding values more intuitively than a list using an index is | cs1qa | null | null | null | null | null | Question:
You created two tasks by using a class.
So, what do you think is the advantage of class?
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
class Card:
pass
def initialize():
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
random.shuffle(cards)
def convert():
for i in range(24):
img = cards[i][0]
name = cards[i][1]
cards[i] = Card()
cards[i].img = img
cards[i].name = name
cards[i].correct = False
def print_cards(num=[]):
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
if i in num:
cards[i].img.moveTo(i_w + w, i_h+h)
canvas.add(cards[i].img)
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
if (cards[num1].correct) or (cards[num2].correct):
return False
if num1==num2:
return False
if not (num1>=0 and num1<24 and num2>=0 and num2<24):
return False
return True
def check(num1, num2):
l=[]
for i in range(24):
if cards[i].correct:
l.append(i)
print_cards([num1, num2]+l)
if cards[num1].name==cards[num2].name:
cards[num1].correct = True
cards[num2].correct = True
return True
else:
print_cards(l)
return False
initialize()
convert()
print_cards(list(range(len(num_pads))))
print_cards()
print("### Welcome to the Python Memento game!!! ###")
l=[]
for i in range(24):
if cards[i].correct:
l.append(i)
while len(l)<24:
print(str(tries) + "th try. You got " + str(len(l)//2) + " pairs.")
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
tries+=1
|
9 | 0 | TA | What does assert do in the Card class? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_pairs = 0
class Card():
def __init__(self, name, img):
self.name = name
self.img = img
self.state = False
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
cards.append(Card(names[i], img))
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
# random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if cards[i].state: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i].img.moveTo(i_w + w, i_h+h)
canvas.add(cards[i].img)
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
if num1!=num2 and num1<=23 and num1>=0 and num2>=0 and num2<=23 and cards[num1].state == False and cards[num2].state == False:
return True
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
cards[num1].state = True
cards[num2].state = True
print_cards()
cards[num1].state = False
cards[num2].state = False
if cards[num1].name==cards[num2].name:
cards[num1].state = True
cards[num2].state = True
print_cards()
global correct_pairs
correct_pairs += 1
return True
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
if correct_pairs==12:
break
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(correct_pairs) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries+=1
###########################################################################
| null | null | variable | I haven't used it, but if you look at the video, it checks if the argument you put in the constructor is an appropriate card name. | cs1qa | null | null | null | null | null | Question:
What does assert do in the Card class?
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
correct_pairs = 0
class Card():
def __init__(self, name, img):
self.name = name
self.img = img
self.state = False
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
cards.append(Card(names[i], img))
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
# random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if cards[i].state: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i].img.moveTo(i_w + w, i_h+h)
canvas.add(cards[i].img)
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
if num1!=num2 and num1<=23 and num1>=0 and num2>=0 and num2<=23 and cards[num1].state == False and cards[num2].state == False:
return True
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
cards[num1].state = True
cards[num2].state = True
print_cards()
cards[num1].state = False
cards[num2].state = False
if cards[num1].name==cards[num2].name:
cards[num1].state = True
cards[num2].state = True
print_cards()
global correct_pairs
correct_pairs += 1
return True
print_cards()
return False
initialize()
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while True: # 3-2-3. Rewrite the condition for termination
###############################################################################
if correct_pairs==12:
break
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(correct_pairs) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries+=1
###########################################################################
|
5 | 0 | TA | Please explain how you used the global variable in task 1! | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance = balance + money
print("you deposited "+ str(money)+" won")
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance > money :
balance = balance - money
print("you've withdrawed "+ str(money)+" won")
else :
print("you've withdrawed "+str(money)+" won")
print("but you only have "+str(balance)+" won")
#################
### implement ###
#################
# Do something on here !
pass
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
global balance
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process == 'd' :
money = int(input ("How much do you want to deposit? "))
deposit(money)
continue
elif process == 'w' :
money = int(input ("How much do you want to withdraw? "))
withdrawal(money)
continue
elif process == 'c' :
print("your current balance is "+ str(balance) +" won")
continue
elif process == '' :
return
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
| 0 | 36 | variable | The global variable allows you to directly access the variable when using a function, so you can change the balance value directly inside the function. | cs1qa | null | null | null | null | null | Question:
Please explain how you used the global variable in task 1!
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
# Do something on here !
global balance
balance = balance + money
print("you deposited "+ str(money)+" won")
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
global balance
if balance > money :
balance = balance - money
print("you've withdrawed "+ str(money)+" won")
else :
print("you've withdrawed "+str(money)+" won")
print("but you only have "+str(balance)+" won")
#################
### implement ###
#################
# Do something on here !
pass
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
global balance
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process == 'd' :
money = int(input ("How much do you want to deposit? "))
deposit(money)
continue
elif process == 'w' :
money = int(input ("How much do you want to withdraw? "))
withdrawal(money)
continue
elif process == 'c' :
print("your current balance is "+ str(balance) +" won")
continue
elif process == '' :
return
# If a user's input is empty string (''), then quit this function.
# If a user's input is 'd', then ask the amount of money to deposit and deposit it.
# If a user's input is 'w', then ask the amount of money to withdraw and withdraw it.
# If a user's input is 'c', then check the current balance.
#################
### implement ###
#################
# Do something on here !
pass
#################
bank()
|
3 | 4 | TA | In task5, what criteria was yellow, green, and blue divided by?? | from cs1media import *
# This code converts an image into a black & white poster.
threshold = 100
white = (255, 255, 255)
black = (0, 0, 0)
image = load_picture('./images/minion.jpg')
width, height = image.size()
# for y in range(height):
# for x in range(width):
# r, g, b = image.get(x, y)
# average_brightness = (r + g + b) // 3
# if average_brightness > threshold:
# image.set(x, y, white)
# else:
# image.set(x, y, black)
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
threshold1 = 85
threshold2 = 170
for y in range(height):
for x in range(width):
r, g, b = image.get(x, y)
average_brightness = (r + g + b) // 3
if average_brightness > threshold2:
image.set(x, y, yellow)
elif average_brightness > threshold1:
image.set(x, y, green)
else:
image.set(x, y, blue)
image.show() | 25 | 37 | code_explain | I used 255 times 1/3 times 2/3 times. | cs1qa | null | null | null | null | null | Question:
In task5, what criteria was yellow, green, and blue divided by??
Code:
from cs1media import *
# This code converts an image into a black & white poster.
threshold = 100
white = (255, 255, 255)
black = (0, 0, 0)
image = load_picture('./images/minion.jpg')
width, height = image.size()
# for y in range(height):
# for x in range(width):
# r, g, b = image.get(x, y)
# average_brightness = (r + g + b) // 3
# if average_brightness > threshold:
# image.set(x, y, white)
# else:
# image.set(x, y, black)
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
threshold1 = 85
threshold2 = 170
for y in range(height):
for x in range(width):
r, g, b = image.get(x, y)
average_brightness = (r + g + b) // 3
if average_brightness > threshold2:
image.set(x, y, yellow)
elif average_brightness > threshold1:
image.set(x, y, green)
else:
image.set(x, y, blue)
image.show() |
1 | 3 | TA | Please briefly explain the behavior of next_line and next_line2 in task 4! | from cs1robots import *
# create_world()
# load_world('worlds/world_file_name.wld')
load_world('worlds/harvest1.wld')
hubo = Robot()
hubo.set_trace('blue')
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest_one_line():
for i in range(5):
hubo.pick_beeper()
hubo.move()
hubo.pick_beeper()
def next_line():
hubo.turn_left()
hubo.move()
hubo.turn_left()
def next_line_2():
turn_right()
hubo.move()
turn_right()
for i in range(2):
harvest_one_line()
next_line()
harvest_one_line()
next_line_2()
harvest_one_line()
next_line()
harvest_one_line() | 19 | 27 | variable | next_line is an action to move from the odd numbered line to the even numbered line
next_line2 moves from even to odd lines! | cs1qa | null | null | null | null | null | Question:
Please briefly explain the behavior of next_line and next_line2 in task 4!
Code:
from cs1robots import *
# create_world()
# load_world('worlds/world_file_name.wld')
load_world('worlds/harvest1.wld')
hubo = Robot()
hubo.set_trace('blue')
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest_one_line():
for i in range(5):
hubo.pick_beeper()
hubo.move()
hubo.pick_beeper()
def next_line():
hubo.turn_left()
hubo.move()
hubo.turn_left()
def next_line_2():
turn_right()
hubo.move()
turn_right()
for i in range(2):
harvest_one_line()
next_line()
harvest_one_line()
next_line_2()
harvest_one_line()
next_line()
harvest_one_line() |
10 | 0 | TA | What is boost() function? | from cs1graphics import *
from time import sleep
_scene = None
_world = None
t = 0.2
def create_world():
global _scene, _world
if _scene:
raise RuntimeError("A world already exists!")
_world = _World(500, 300)
_scene = Canvas(_world.width, _world.height)
_scene.setTitle("Mario World")
_world.draw_scene()
class _World(object):
def __init__(self, width, height):
self.width = width
self.height = height
def draw_scene(self):
"""
draw background here
Don't forget _scene.add(name)
"""
grass = Rectangle(1000, 150, Point(250, 250))
grass.setFillColor('green')
grass.setDepth(100)
_scene.add(grass)
#blocks
block = Rectangle(40, 40, Point(200, 100))
block.setFillColor('brown')
qmark = Text("?", 20, Point(200, 100))
qmark.setFontColor('Yellow')
qmark.setDepth(48)
_scene.add(qmark)
block2 = block.clone()
block2.move(40, 0)
block.setDepth(50)
_scene.add(block)
_scene.add(block2)
#pipe
pipe = Polygon(Point(400, 150), Point(400, 160), Point(410, 160), Point(410, 320), Point(470, 320), Point(470, 160), Point(480, 160), Point(480, 150))
pipe.setFillColor('lightgreen')
pipe.setDepth(10)
pipe.move(-10, 0)
_scene.add(pipe)
class Mushroom(object):
def __init__(self, x=200, y=92):
mushroom = Layer()
uppermush = Ellipse(38, 18, Point(x, y))
uppermush.setFillColor('red')
uppermush.setDepth(52)
lowermush = Ellipse(35, 25, Point(x, y+8))
lowermush.setFillColor('beige')
lowermush.setDepth(53)
mushroom.add(lowermush)
mushroom.add(uppermush)
mushroom.setDepth(52)
self.layer = mushroom
_scene.add(self.layer)
def diappear(self):
self.layer.scale(0.001)
def move(self, x, y):
self.layer.move(x, y)
def arise(self):
self.layer.setDepth(45)
self.layer.move(0, -20)
COLOR = ['Red', 'Blue']
TYPE = ['super', 'normal']
class Mario(object):
def __init__(self, color='Blue', type='normal'):
assert type in TYPE and color in COLOR
self.color = color
self.type = type
self.step_size = 3
# Constructing Mario
mario = Layer()
# body
body = Rectangle(33, 22, Point(200, 200))
body.setFillColor(color)
body.setDepth(50)
mario.add(body)
# face
face = Ellipse(30, 20, Point(200, 180))
face.setFillColor('beige')
face.setDepth(40)
mario.add(face)
#hat
hat = Polygon(Point(185, 175), Point(220, 175), Point(220, 173), Point(215, 173), Point(212, 168), Point(188, 168))
hat.setFillColor(color)
hat.setDepth(39)
mario.add(hat)
#beard
beard = Polygon(Point(207, 183), Point(217, 183), Point(215, 180), Point(209, 180))
beard.setFillColor('Brown')
beard.setDepth(38)
mario.add(beard)
shoe = Layer()
#left shoe
lshoe = Rectangle(15, 6, Point(191, 215))
lshoe.setFillColor('black')
lshoe.setDepth(52)
shoe.add(lshoe)
#right shoe
rshoe = lshoe.clone()
rshoe.move(17, 0)
shoe.add(rshoe)
mario.add(shoe)
# save alias of moveable parts
self.layer = mario
self.body = body
self.hat = hat
self.shoe = shoe
_scene.add(self.layer)
self.moving_part_count = 0
if type == 'super':
self.supermario()
def shoe_move(self):
if self.moving_part_count % 3 == 0:
self.shoe.move(3, 0)
elif self.moving_part_count % 3 == 1:
self.shoe.move(-5,0)
else: self.shoe.move(2,0)
self.moving_part_count += 1
if self.moving_part_count % 3 == 0: self.moving_part_count = 0
def move(self,x=10,y=0):
self.layer.move(x,y)
def supermario(self):
tempPt = self.body.getReferencePoint()
self.layer.adjustReference(tempPt.getX(), tempPt.getY())
for i in range(3):
self.layer.scale(1.3)
sleep(t/2)
self.layer.scale(0.9)
sleep(t/2)
def walk(self,x=20):
assert x > 0
total_step = int(x / self.step_size)
for i in range(total_step):
sleep(t/4)
self.move(self.step_size, 0)
self.shoe_move()
def show_animation():
sleep(t)
mario.move(0, -50)
mushroom.arise()
sleep(t)
mario.move(0, 50)
mushroom.move(0, 8)
for i in range(7):
sleep(t/2)
mushroom.move(10, 0)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
sleep(t/2)
mushroom.move(0, 50)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
sleep(t)
mushroom.move(0, 50)
sleep(t/2)
mushroom.diappear()
sleep(t/2)
mario.supermario()
for i in range(6):
sleep(t/2)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
for i in range(2):
sleep(t)
mario.move(28, -60)
for i in range(1):
sleep(t)
mario.move(32, 40)
sleep(2*t)
for i in range(4):
sleep(t)
mario.move(0, 25)
def interactive_example():
while True:
e = _scene.wait()
d = e.getDescription()
if d == "keyboard":
k = e.getKey()
if k == "q":
_scene.close()
break
elif k == "w":
mario.walk(20)
elif k == "r":
mario.walk(40)
elif k == "j":
mario.move(0, -50)
sleep(t)
mario.move(0, 50)
create_world()
mario = Mario('Blue', 'normal')
mushroom = Mushroom(200, 92)
show_animation()
# interactive_example()
| null | null | variable | That's a function where hulk grows by 1.1 times at intervals of t/5.
I repeated it 10 times | cs1qa | null | null | null | null | null | Question:
What is boost() function?
Code:
from cs1graphics import *
from time import sleep
_scene = None
_world = None
t = 0.2
def create_world():
global _scene, _world
if _scene:
raise RuntimeError("A world already exists!")
_world = _World(500, 300)
_scene = Canvas(_world.width, _world.height)
_scene.setTitle("Mario World")
_world.draw_scene()
class _World(object):
def __init__(self, width, height):
self.width = width
self.height = height
def draw_scene(self):
"""
draw background here
Don't forget _scene.add(name)
"""
grass = Rectangle(1000, 150, Point(250, 250))
grass.setFillColor('green')
grass.setDepth(100)
_scene.add(grass)
#blocks
block = Rectangle(40, 40, Point(200, 100))
block.setFillColor('brown')
qmark = Text("?", 20, Point(200, 100))
qmark.setFontColor('Yellow')
qmark.setDepth(48)
_scene.add(qmark)
block2 = block.clone()
block2.move(40, 0)
block.setDepth(50)
_scene.add(block)
_scene.add(block2)
#pipe
pipe = Polygon(Point(400, 150), Point(400, 160), Point(410, 160), Point(410, 320), Point(470, 320), Point(470, 160), Point(480, 160), Point(480, 150))
pipe.setFillColor('lightgreen')
pipe.setDepth(10)
pipe.move(-10, 0)
_scene.add(pipe)
class Mushroom(object):
def __init__(self, x=200, y=92):
mushroom = Layer()
uppermush = Ellipse(38, 18, Point(x, y))
uppermush.setFillColor('red')
uppermush.setDepth(52)
lowermush = Ellipse(35, 25, Point(x, y+8))
lowermush.setFillColor('beige')
lowermush.setDepth(53)
mushroom.add(lowermush)
mushroom.add(uppermush)
mushroom.setDepth(52)
self.layer = mushroom
_scene.add(self.layer)
def diappear(self):
self.layer.scale(0.001)
def move(self, x, y):
self.layer.move(x, y)
def arise(self):
self.layer.setDepth(45)
self.layer.move(0, -20)
COLOR = ['Red', 'Blue']
TYPE = ['super', 'normal']
class Mario(object):
def __init__(self, color='Blue', type='normal'):
assert type in TYPE and color in COLOR
self.color = color
self.type = type
self.step_size = 3
# Constructing Mario
mario = Layer()
# body
body = Rectangle(33, 22, Point(200, 200))
body.setFillColor(color)
body.setDepth(50)
mario.add(body)
# face
face = Ellipse(30, 20, Point(200, 180))
face.setFillColor('beige')
face.setDepth(40)
mario.add(face)
#hat
hat = Polygon(Point(185, 175), Point(220, 175), Point(220, 173), Point(215, 173), Point(212, 168), Point(188, 168))
hat.setFillColor(color)
hat.setDepth(39)
mario.add(hat)
#beard
beard = Polygon(Point(207, 183), Point(217, 183), Point(215, 180), Point(209, 180))
beard.setFillColor('Brown')
beard.setDepth(38)
mario.add(beard)
shoe = Layer()
#left shoe
lshoe = Rectangle(15, 6, Point(191, 215))
lshoe.setFillColor('black')
lshoe.setDepth(52)
shoe.add(lshoe)
#right shoe
rshoe = lshoe.clone()
rshoe.move(17, 0)
shoe.add(rshoe)
mario.add(shoe)
# save alias of moveable parts
self.layer = mario
self.body = body
self.hat = hat
self.shoe = shoe
_scene.add(self.layer)
self.moving_part_count = 0
if type == 'super':
self.supermario()
def shoe_move(self):
if self.moving_part_count % 3 == 0:
self.shoe.move(3, 0)
elif self.moving_part_count % 3 == 1:
self.shoe.move(-5,0)
else: self.shoe.move(2,0)
self.moving_part_count += 1
if self.moving_part_count % 3 == 0: self.moving_part_count = 0
def move(self,x=10,y=0):
self.layer.move(x,y)
def supermario(self):
tempPt = self.body.getReferencePoint()
self.layer.adjustReference(tempPt.getX(), tempPt.getY())
for i in range(3):
self.layer.scale(1.3)
sleep(t/2)
self.layer.scale(0.9)
sleep(t/2)
def walk(self,x=20):
assert x > 0
total_step = int(x / self.step_size)
for i in range(total_step):
sleep(t/4)
self.move(self.step_size, 0)
self.shoe_move()
def show_animation():
sleep(t)
mario.move(0, -50)
mushroom.arise()
sleep(t)
mario.move(0, 50)
mushroom.move(0, 8)
for i in range(7):
sleep(t/2)
mushroom.move(10, 0)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
sleep(t/2)
mushroom.move(0, 50)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
sleep(t)
mushroom.move(0, 50)
sleep(t/2)
mushroom.diappear()
sleep(t/2)
mario.supermario()
for i in range(6):
sleep(t/2)
mario.move(10, 0)
mario.shoe_move()
sleep(t/2)
mario.shoe_move()
for i in range(2):
sleep(t)
mario.move(28, -60)
for i in range(1):
sleep(t)
mario.move(32, 40)
sleep(2*t)
for i in range(4):
sleep(t)
mario.move(0, 25)
def interactive_example():
while True:
e = _scene.wait()
d = e.getDescription()
if d == "keyboard":
k = e.getKey()
if k == "q":
_scene.close()
break
elif k == "w":
mario.walk(20)
elif k == "r":
mario.walk(40)
elif k == "j":
mario.move(0, -50)
sleep(t)
mario.move(0, 50)
create_world()
mario = Mario('Blue', 'normal')
mushroom = Mushroom(200, 92)
show_animation()
# interactive_example()
|
6 | 1 | TA | Why did you use set() in count_integers() in task2? | from random import *
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
arr = []
for i in range(trials):
x = randint(lb,ub)
arr.append(x)
return arr
pass
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
s = 0
for i in range(len(num_list)):
s += num_list[i]
return s/len(num_list)
pass
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
list1 = list(set(num_list))
list2 = []
for i in range(len(list1)):
list2.append((list1[i], num_list.count(list1[i])))
return list2
pass
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
| 31 | 42 | reasoning | After removing the duplicated elements in advance, I saved a tuple of elements and number of elements in list2. | cs1qa | null | null | null | null | null | Question:
Why did you use set() in count_integers() in task2?
Code:
from random import *
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
arr = []
for i in range(trials):
x = randint(lb,ub)
arr.append(x)
return arr
pass
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
s = 0
for i in range(len(num_list)):
s += num_list[i]
return s/len(num_list)
pass
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
list1 = list(set(num_list))
list2 = []
for i in range(len(list1)):
list2.append((list1[i], num_list.count(list1[i])))
return list2
pass
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
|
1 | 4 | TA | Can you briefly explain turn_right? | from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
hubo.set_trace('light green')
def turn_right():
for i in range(3):
hubo.turn_left()
def u_turn_R():
for i in range(2):
hubo.move()
turn_right()
def u_turn_L():
for i in range(2):
hubo.move()
hubo.turn_left()
def u_turn_R2():
for i in range(2):
turn_right()
hubo.move()
def u_turn_L2():
for i in range(2):
hubo.turn_left()
hubo.move()
def harvest_moving():
hubo.pick_beeper()
hubo.move()
hubo.move()
def harvest(x):
for i in range(x):
harvest_moving()
hubo.pick_beeper()
hubo.turn_left()
for i in range(6):
hubo.move()
hubo.pick_beeper()
for i in range(5):
if i%2==0:
u_turn_R()
harvest(i+1)
else:
u_turn_L()
harvest(i+1)
for i in range(5):
if i%2==0 :
u_turn_L2()
harvest(4-i)
else :
u_turn_R2()
harvest(4-i) | 7 | 9 | variable | turn_right is a function that rotates to the right | cs1qa | null | null | null | null | null | Question:
Can you briefly explain turn_right?
Code:
from cs1robots import*
load_world('worlds/harvest2.wld')
hubo=Robot()
hubo.set_trace('light green')
def turn_right():
for i in range(3):
hubo.turn_left()
def u_turn_R():
for i in range(2):
hubo.move()
turn_right()
def u_turn_L():
for i in range(2):
hubo.move()
hubo.turn_left()
def u_turn_R2():
for i in range(2):
turn_right()
hubo.move()
def u_turn_L2():
for i in range(2):
hubo.turn_left()
hubo.move()
def harvest_moving():
hubo.pick_beeper()
hubo.move()
hubo.move()
def harvest(x):
for i in range(x):
harvest_moving()
hubo.pick_beeper()
hubo.turn_left()
for i in range(6):
hubo.move()
hubo.pick_beeper()
for i in range(5):
if i%2==0:
u_turn_R()
harvest(i+1)
else:
u_turn_L()
harvest(i+1)
for i in range(5):
if i%2==0 :
u_turn_L2()
harvest(4-i)
else :
u_turn_R2()
harvest(4-i) |
5 | 0 | TA | Task 1. Please explain the role of the Withdrawal function. | balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
plus=int(input('How much you want to deposit'))
print('you deposit %d won'%plus)
global balance
balance=money+plus
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
minus=int(input('How much you want to withdraw'))
if money>=minus:
print('you withdraw %d won'%minus)
global balance
balance=money-minus
else:
print('you withdraw %d won'%minus)
print('But you only have %d'%money)
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='d':
deposit(balance)
elif process=='w':
withdrawal(balance)
elif process=='c':
print('Your current balance is %d won'%balance)
else:
print('Please, press d or w or c or return')
return False
#################
### implement ###
#################
# Do something on here !
#################
bank()
| 17 | 35 | variable | The withdrawal function receives the desired amount of deposit and compares it with the money in the bankbook, and prints a message stating that the amount of money remaining in the bankbook is larger and less, and the deposit is not made. | cs1qa | null | null | null | null | null | Question:
Task 1. Please explain the role of the Withdrawal function.
Code:
balance = 0
def deposit(money) :
# Input : (Integer) The amount of money that a user wants to deposit
# Output : (None) No Output
# Add the money to the current balance
#################
### implement ###
#################
plus=int(input('How much you want to deposit'))
print('you deposit %d won'%plus)
global balance
balance=money+plus
#################
def withdrawal(money) :
# Input : (Integer) The amount of money that a user wants to withdraw
# Output : (None) No Output
# Withdraw the money from the current balance
#################
### implement ###
#################
# Do something on here !
minus=int(input('How much you want to withdraw'))
if money>=minus:
print('you withdraw %d won'%minus)
global balance
balance=money-minus
else:
print('you withdraw %d won'%minus)
print('But you only have %d'%money)
#################
def bank() :
# Input : (None) No Input
# Output : (None) No Output
while True:
process = input("Deposit(d) or withdrawal(w) or balance check(c)? ")
if process=='d':
deposit(balance)
elif process=='w':
withdrawal(balance)
elif process=='c':
print('Your current balance is %d won'%balance)
else:
print('Please, press d or w or c or return')
return False
#################
### implement ###
#################
# Do something on here !
#################
bank()
|
5 | 1 | TA | Are draw_animal() and show_animation() purposely created separately?? | from cs1graphics import *
from time import sleep
def draw_animal():
# Implement this function.
paper = Canvas()
paper.setWidth(500)
paper.setHeight(200)
Tank = Layer()
tire1 = Circle(12, Point(-12, -5))
tire2 = Circle(12, Point(12, -5))
tire3 = Circle(12, Point(35, -5))
tire4 = Circle(12, Point(-35, -5))
body = Rectangle(70, 40, Point(0,-20))
head2 = Rectangle(50, 5, Point(50, -30))
tire1.setFillColor('black')
tire2.setFillColor('black')
tire3.setFillColor('black')
tire4.setFillColor('black')
body.setFillColor('green')
head2.setFillColor('red')
body.setDepth(60)
Tank.add(tire1)
Tank.add(tire2)
Tank.add(tire3)
Tank.add(tire4)
Tank.add(body)
Tank.add(head2)
paper.add(Tank)
Tank.moveTo(250, 100)
def show_animation():
# Implement this function.
paper = Canvas()
paper.setWidth(500)
paper.setHeight(200)
Tank = Layer()
tire1 = Circle(12, Point(-12, -5))
tire2 = Circle(12, Point(12, -5))
tire3 = Circle(12, Point(35, -5))
tire4 = Circle(12, Point(-35, -5))
body = Rectangle(70, 40, Point(0,-20))
head2 = Rectangle(50, 5, Point(50, -30))
tire1.setFillColor('black')
tire2.setFillColor('black')
tire3.setFillColor('black')
tire4.setFillColor('black')
body.setFillColor('green')
head2.setFillColor('red')
body.setDepth(60)
Tank.add(tire1)
Tank.add(tire2)
Tank.add(tire3)
Tank.add(tire4)
Tank.add(body)
Tank.add(head2)
paper.add(Tank)
Tank.moveTo(0, 100)
delay = 0.2
for i in range(50):
Tank.move(8,0)
head2.move(0,10)
sleep(delay)
head2.move(0, -10)
sleep(delay)
draw_animal()
show_animation() | 3 | 91 | reasoning | Oh, it wasn't on purpose, but I think it happened because I tried to print it out with the animation | cs1qa | null | null | null | null | null | Question:
Are draw_animal() and show_animation() purposely created separately??
Code:
from cs1graphics import *
from time import sleep
def draw_animal():
# Implement this function.
paper = Canvas()
paper.setWidth(500)
paper.setHeight(200)
Tank = Layer()
tire1 = Circle(12, Point(-12, -5))
tire2 = Circle(12, Point(12, -5))
tire3 = Circle(12, Point(35, -5))
tire4 = Circle(12, Point(-35, -5))
body = Rectangle(70, 40, Point(0,-20))
head2 = Rectangle(50, 5, Point(50, -30))
tire1.setFillColor('black')
tire2.setFillColor('black')
tire3.setFillColor('black')
tire4.setFillColor('black')
body.setFillColor('green')
head2.setFillColor('red')
body.setDepth(60)
Tank.add(tire1)
Tank.add(tire2)
Tank.add(tire3)
Tank.add(tire4)
Tank.add(body)
Tank.add(head2)
paper.add(Tank)
Tank.moveTo(250, 100)
def show_animation():
# Implement this function.
paper = Canvas()
paper.setWidth(500)
paper.setHeight(200)
Tank = Layer()
tire1 = Circle(12, Point(-12, -5))
tire2 = Circle(12, Point(12, -5))
tire3 = Circle(12, Point(35, -5))
tire4 = Circle(12, Point(-35, -5))
body = Rectangle(70, 40, Point(0,-20))
head2 = Rectangle(50, 5, Point(50, -30))
tire1.setFillColor('black')
tire2.setFillColor('black')
tire3.setFillColor('black')
tire4.setFillColor('black')
body.setFillColor('green')
head2.setFillColor('red')
body.setDepth(60)
Tank.add(tire1)
Tank.add(tire2)
Tank.add(tire3)
Tank.add(tire4)
Tank.add(body)
Tank.add(head2)
paper.add(Tank)
Tank.moveTo(0, 100)
delay = 0.2
for i in range(50):
Tank.move(8,0)
head2.move(0,10)
sleep(delay)
head2.move(0, -10)
sleep(delay)
draw_animal()
show_animation() |
2 | 1 | student | I am not entirely sure about my definition of plant | import time
from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot(beepers=5)
time.sleep(0.5)
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def plant():
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.drop_beeper()
else:
hubo.drop_beeper()
def move_forward():
for i in range (5):
plant()
def move_one():
hubo.turn_left()
plant()
hubo.turn_left()
move_forward()
turn_right()
plant()
turn_right()
move_forward()
def move_two():
for i in range(2):
move_one()
plant()
move_forward()
move_two()
hubo.turn_left()
plant()
hubo.turn_left()
move_forward()
plant() | 9 | 15 | code_understanding | You have the right idea for "plant" | cs1qa | null | null | null | null | null | Question:
I am not entirely sure about my definition of plant
Code:
import time
from cs1robots import *
load_world("worlds/harvest3.wld")
hubo = Robot(beepers=5)
time.sleep(0.5)
hubo.set_trace("blue")
def turn_right():
for i in range(3):
hubo.turn_left()
def plant():
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
hubo.drop_beeper()
else:
hubo.drop_beeper()
def move_forward():
for i in range (5):
plant()
def move_one():
hubo.turn_left()
plant()
hubo.turn_left()
move_forward()
turn_right()
plant()
turn_right()
move_forward()
def move_two():
for i in range(2):
move_one()
plant()
move_forward()
move_two()
hubo.turn_left()
plant()
hubo.turn_left()
move_forward()
plant() |
3 | 0 | TA | Explain lines 8-9 in task1 | from cs1robots import *
create_world()
my_robot = Robot(orientation='W', avenue=7, street=5)
my_robot.set_trace('blue')
while not my_robot.facing_north():
my_robot.turn_left()
my_robot.turn_left()
while my_robot.front_is_clear():
my_robot.move()
my_robot.turn_left()
while my_robot.front_is_clear():
my_robot.move()
my_robot.turn_left()
| 7 | 9 | code_explain | Turn until you see north, and when you see north, you look west by line 10 | cs1qa | null | null | null | null | null | Question:
Explain lines 8-9 in task1
Code:
from cs1robots import *
create_world()
my_robot = Robot(orientation='W', avenue=7, street=5)
my_robot.set_trace('blue')
while not my_robot.facing_north():
my_robot.turn_left()
my_robot.turn_left()
while my_robot.front_is_clear():
my_robot.move()
my_robot.turn_left()
while my_robot.front_is_clear():
my_robot.move()
my_robot.turn_left()
|
4 | 0 | TA | Briefly explain what algorithm you wrote in Task 1! | from cs1robots import *
import time
load_world('worlds/add34.wld')
hubo = Robot()
#Defining functions
def turn_right():
for i in range(3):
hubo.turn_left()
def turn_around():
for i in range(2):
hubo.turn_left()
def Sum(a, b):
return a+b
#Main algorithm
number_of_beeper = 0
Number_in_row1 = 0
Number_in_row2 = 0
Sum = 0
hubo.turn_left()
hubo.move()
turn_right()
for i in range(10):
if hubo.on_beeper():
number_of_beeper = 0
x, y = hubo.get_pos()
while hubo.on_beeper():
hubo.pick_beeper()
number_of_beeper += 1
Number_in_row2 += (10**(10-x)) * number_of_beeper
if hubo.front_is_clear(): hubo.move()
turn_right()
hubo.move()
turn_right()
for i in range(10):
if hubo.on_beeper():
number_of_beeper = 0
x, y = hubo.get_pos()
while hubo.on_beeper():
hubo.pick_beeper()
number_of_beeper += 1
Number_in_row1 += (10**(10-x)) * number_of_beeper
if hubo.front_is_clear(): hubo.move()
turn_around()
print(Number_in_row1, Number_in_row2)
Sum = Number_in_row1 + Number_in_row2
print(Sum)
a = int(Sum/1000)
b = int((Sum-1000*a)/100)
c = int((Sum-1000*a-100*b)/10)
d = int(Sum-1000*a-100*b-10*c)
print(a, b, c, d)
for i in range(6): hubo.move()
for i in range(a): hubo.drop_beeper()
hubo.move()
for i in range(b): hubo.drop_beeper()
hubo.move()
for i in range(c): hubo.drop_beeper()
hubo.move()
for i in range(d): hubo.drop_beeper()
turn_around()
for i in range(9): hubo.move() | 0 | 77 | code_explain | Pick up the beepers in row1 and row2, store the number represented by each row in Number_in_row1 and Number_in_row2, respectively, proceed with addition, and display the corresponding result as beeper in row1. | cs1qa | null | null | null | null | null | Question:
Briefly explain what algorithm you wrote in Task 1!
Code:
from cs1robots import *
import time
load_world('worlds/add34.wld')
hubo = Robot()
#Defining functions
def turn_right():
for i in range(3):
hubo.turn_left()
def turn_around():
for i in range(2):
hubo.turn_left()
def Sum(a, b):
return a+b
#Main algorithm
number_of_beeper = 0
Number_in_row1 = 0
Number_in_row2 = 0
Sum = 0
hubo.turn_left()
hubo.move()
turn_right()
for i in range(10):
if hubo.on_beeper():
number_of_beeper = 0
x, y = hubo.get_pos()
while hubo.on_beeper():
hubo.pick_beeper()
number_of_beeper += 1
Number_in_row2 += (10**(10-x)) * number_of_beeper
if hubo.front_is_clear(): hubo.move()
turn_right()
hubo.move()
turn_right()
for i in range(10):
if hubo.on_beeper():
number_of_beeper = 0
x, y = hubo.get_pos()
while hubo.on_beeper():
hubo.pick_beeper()
number_of_beeper += 1
Number_in_row1 += (10**(10-x)) * number_of_beeper
if hubo.front_is_clear(): hubo.move()
turn_around()
print(Number_in_row1, Number_in_row2)
Sum = Number_in_row1 + Number_in_row2
print(Sum)
a = int(Sum/1000)
b = int((Sum-1000*a)/100)
c = int((Sum-1000*a-100*b)/10)
d = int(Sum-1000*a-100*b-10*c)
print(a, b, c, d)
for i in range(6): hubo.move()
for i in range(a): hubo.drop_beeper()
hubo.move()
for i in range(b): hubo.drop_beeper()
hubo.move()
for i in range(c): hubo.drop_beeper()
hubo.move()
for i in range(d): hubo.drop_beeper()
turn_around()
for i in range(9): hubo.move() |
4 | 0 | TA | Why did you use the while statement?? | def fibonacci(upper_bound):
pass
result = [0, 1]
while True:
result.append(result[-1]+result[-2])
if result[-1] >= upper_bound:
result.remove(result[-1])
return(result)
print(fibonacci(1000))
| 5 | 7 | reasoning | It is to repeat until the upper_bound is exceeded, and when the condition is satisfied, it is finished with return. | cs1qa | null | null | null | null | null | Question:
Why did you use the while statement??
Code:
def fibonacci(upper_bound):
pass
result = [0, 1]
while True:
result.append(result[-1]+result[-2])
if result[-1] >= upper_bound:
result.remove(result[-1])
return(result)
print(fibonacci(1000))
|
1 | 0 | TA | Please briefly explain what a lambda function is | from cs1robots import *
create_world()
rb = Robot() # \Robo_HEAD/
def rpt(fu, i, args=()): # repeat
for x in range(i):
fu.__call__(*args)
tl = lambda : rb.turn_left()
tr = lambda : rpt(rb.turn_left, 3)
mv = lambda i : rpt(rb.move, i)
def setup():
tl()
rb.set_trace("blue")
def foo():
mv(9); tr(); mv(1); tr(); mv(9);
def bar():
tl(); mv(1); tl();
def foobar():
foo(); bar();
if __name__=="__main__":
setup()
rpt(foobar, 4)
foo()
| 8 | 10 | variable | Anonymous function, function without name
It is derived from the lambda calculation method suggested by Alonzo Church.
If func1 = lambda x: 2x
def func1(x):
return 2*x
I feel like | cs1qa | null | null | null | null | null | Question:
Please briefly explain what a lambda function is
Code:
from cs1robots import *
create_world()
rb = Robot() # \Robo_HEAD/
def rpt(fu, i, args=()): # repeat
for x in range(i):
fu.__call__(*args)
tl = lambda : rb.turn_left()
tr = lambda : rpt(rb.turn_left, 3)
mv = lambda i : rpt(rb.move, i)
def setup():
tl()
rb.set_trace("blue")
def foo():
mv(9); tr(); mv(1); tr(); mv(9);
def bar():
tl(); mv(1); tl();
def foobar():
foo(); bar();
if __name__=="__main__":
setup()
rpt(foobar, 4)
foo()
|
2 | 0 | TA | What does the zigzag function in task1 do? | from cs1robots import *
load_world('worlds/harvest3.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
def zigzag():
for i in range(5):
harvest()
hubo.turn_left()
harvest()
hubo.turn_left()
for i in range(5):
harvest()
#
hubo.move()
zigzag()
turn_right()
harvest()
turn_right()
zigzag()
turn_right()
harvest()
turn_right()
zigzag()
#harvest_more() | 14 | 21 | variable | Going all the time, picking up all the beepers
Picking up the beeper
It comes back all the time and picks up the beeper
Is a function | cs1qa | null | null | null | null | null | Question:
What does the zigzag function in task1 do?
Code:
from cs1robots import *
load_world('worlds/harvest3.wld')
hubo = Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def harvest():
if hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
def zigzag():
for i in range(5):
harvest()
hubo.turn_left()
harvest()
hubo.turn_left()
for i in range(5):
harvest()
#
hubo.move()
zigzag()
turn_right()
harvest()
turn_right()
zigzag()
turn_right()
harvest()
turn_right()
zigzag()
#harvest_more() |
1 | 0 | TA | Could you explain what kind of implication is the go_and_back function? | from cs1robots import*
create_world()
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def go_straight():
for i in range(9):
hubo.move()
def go_and_back():
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
hubo.turn_left()
for i in range(4):
go_and_back()
hubo.turn_left()
hubo.move()
hubo.turn_left()
go_and_back() | 14 | 19 | variable | It is a function that goes up and down, and goes 2 lines | cs1qa | null | null | null | null | null | Question:
Could you explain what kind of implication is the go_and_back function?
Code:
from cs1robots import*
create_world()
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def go_straight():
for i in range(9):
hubo.move()
def go_and_back():
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
hubo.turn_left()
for i in range(4):
go_and_back()
hubo.turn_left()
hubo.move()
hubo.turn_left()
go_and_back() |
6 | 2 | TA | Please explain the is_valid function in step 3 | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if (correct_list.count(i)==1)or(tries==0): # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range
if (0<=num1)&(num1<=23)&(0<=num2)&(num2<=23)&(num1!=num2)&(correct_list.count(num1)==0)&(correct_list.count(num2)==0):
return True
# Return Boolean value according to the result.
###########################################################################
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
if cards[num1][1]==cards[num2][1]:
print_cards()
return True
print_cards()
correct_list.pop()
correct_list.pop()
print_cards()
return False
initialize()
print_cards()
tries += 1
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
| 62 | 68 | variable | In the case of is_valid, if two numbers to be assigned are 0 or more and 23 or less, they are not equal to each other and are not in the count_list, True is returned. | cs1qa | null | null | null | null | null | Question:
Please explain the is_valid function in step 3
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 0
correct_list = []
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
# 3-2-1. shuffle the card list
random.shuffle(cards)
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if (correct_list.count(i)==1)or(tries==0): # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range
if (0<=num1)&(num1<=23)&(0<=num2)&(num2<=23)&(num1!=num2)&(correct_list.count(num1)==0)&(correct_list.count(num2)==0):
return True
# Return Boolean value according to the result.
###########################################################################
return False
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same,
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
if cards[num1][1]==cards[num2][1]:
print_cards()
return True
print_cards()
correct_list.pop()
correct_list.pop()
print_cards()
return False
initialize()
print_cards()
tries += 1
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while len(correct_list)<24: # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
###########################################################################
|
3 | 4 | TA | How did you do the color classification in task5, and where is the code that makes it blue when dark? | from cs1media import *
# This code converts an image into a black & white poster.
threshold1 = 200
threshold2 = 50
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0,0,255)
image = load_picture('./images/minion.jpg')
width, height = image.size()
for y in range(height):
for x in range(width):
r, g, b = image.get(x, y)
average_brightness = (r + g + b) // 3
if average_brightness > threshold1:
image.set(x, y, yellow)
elif (average_brightness<=threshold1)and(average_brightness>=threshold2):
image.set(x,y, green)
else:
image.set(x, y, blue)
image.show()
| 16 | 21 | code_explain | In the case of task5, the color brightness section was divided into three by setting the threshold as two, respectively, if the brightness is higher than threshold1, the color is set to yellow if the brightness is higher than threshold1 and green if the value is between threshold1 and threshold2, and blue if it is smaller than threshold1
Is code 21-22 | cs1qa | null | null | null | null | null | Question:
How did you do the color classification in task5, and where is the code that makes it blue when dark?
Code:
from cs1media import *
# This code converts an image into a black & white poster.
threshold1 = 200
threshold2 = 50
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0,0,255)
image = load_picture('./images/minion.jpg')
width, height = image.size()
for y in range(height):
for x in range(width):
r, g, b = image.get(x, y)
average_brightness = (r + g + b) // 3
if average_brightness > threshold1:
image.set(x, y, yellow)
elif (average_brightness<=threshold1)and(average_brightness>=threshold2):
image.set(x,y, green)
else:
image.set(x, y, blue)
image.show()
|
9 | 1 | TA | Why did you declare a separate state function in the Card class? | import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
deck=[]
class Card(object):
def __init__(self, suit, face, value, img, state):
self.suit=suit
self.face=face
self.value=value
self.img=Image(img)
self.state=True
def create_deck(number = 1):
for i in range(3):
for j in range(12):
img=img_path+suit_names[i]+"_"+face_names[j]+".png"
first_card=Card(suit_names[i], face_names[j], value[j], img, True)
deck.append(first_card)
random.shuffle(deck)
return deck
def hand_value(hand):
total=0
for card in hand:
total=total+card.value
return total
def card_string(card):
article="a "
if card.face in [8, "Ace"]:
article="an "
return article+str(card.face)+" of "+card.suit
def ask_yesno(prompt):
answer=input(prompt)
if answer=="y":
return True
elif answer=="n":
return False
else:
print("I beg your pardon")
answer=input(prompt)
def draw_card(dealer,player):
depth = 100
x0,y0 = 100,100
x1,y1 = 100,300
dealer_card_num=20
player_card_num=20
bj_board.clear()
hidden_card=Image('./images/Back.png')
for i in range(len(dealer)):
if dealer[i].state==False:
hidden_card.moveTo(x0,y0)
hidden_card.setDepth(depth)
bj_board.add(hidden_card)
x0=x0+dealer_card_num
else:
dealer[i].img.moveTo(x0,y0)
dealer[i].img.setDepth(depth)
bj_board.add(dealer[i].img)
x0=x0+dealer_card_num
for i in range(len(player)):
player[i].img.moveTo(x1,y1)
player[i].img.setDepth(depth)
bj_board.add(player[i].img)
x1=x1+player_card_num
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
main()
| 66 | 67 | reasoning | Initially declared to make the state of all cards False. | cs1qa | null | null | null | null | null | Question:
Why did you declare a separate state function in the Card class?
Code:
import random
from cs1graphics import *
img_path = './images/'
suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
face_names = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
bj_board = Canvas(600, 400, 'dark green', 'Black Jack 101')
deck=[]
class Card(object):
def __init__(self, suit, face, value, img, state):
self.suit=suit
self.face=face
self.value=value
self.img=Image(img)
self.state=True
def create_deck(number = 1):
for i in range(3):
for j in range(12):
img=img_path+suit_names[i]+"_"+face_names[j]+".png"
first_card=Card(suit_names[i], face_names[j], value[j], img, True)
deck.append(first_card)
random.shuffle(deck)
return deck
def hand_value(hand):
total=0
for card in hand:
total=total+card.value
return total
def card_string(card):
article="a "
if card.face in [8, "Ace"]:
article="an "
return article+str(card.face)+" of "+card.suit
def ask_yesno(prompt):
answer=input(prompt)
if answer=="y":
return True
elif answer=="n":
return False
else:
print("I beg your pardon")
answer=input(prompt)
def draw_card(dealer,player):
depth = 100
x0,y0 = 100,100
x1,y1 = 100,300
dealer_card_num=20
player_card_num=20
bj_board.clear()
hidden_card=Image('./images/Back.png')
for i in range(len(dealer)):
if dealer[i].state==False:
hidden_card.moveTo(x0,y0)
hidden_card.setDepth(depth)
bj_board.add(hidden_card)
x0=x0+dealer_card_num
else:
dealer[i].img.moveTo(x0,y0)
dealer[i].img.setDepth(depth)
bj_board.add(dealer[i].img)
x0=x0+dealer_card_num
for i in range(len(player)):
player[i].img.moveTo(x1,y1)
player[i].img.setDepth(depth)
bj_board.add(player[i].img)
x1=x1+player_card_num
def main():
deck = []
while True:
# prompt for starting a new game and create a deck
print ("Welcome to Black Jack 101!\n")
if len(deck) < 12:
deck = create_deck()
# create two hands of dealer and player
dealer = []
player = []
# initial two dealings
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt a hidden card")
card.state=False
dealer.append(card)
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# player's turn to draw cards
while hand_value(player) < 21 and ask_yesno("Would you like another card? (y/n) "):
# draw a card for the player
card = deck.pop()
print ("You are dealt " + card_string(card))
player.append(card)
print ("Your total is", hand_value(player))
draw_card(dealer,player)
# if the player's score is over 21, the player loses immediately.
if hand_value(player) > 21:
print ("You went over 21! You lost.")
dealer[0].state = True
draw_card(dealer,player)
else:
# draw cards for the dealer while the dealer's score is less than 17
print ("\nThe dealer's hidden card was " + card_string(dealer[0]))
while hand_value(dealer) < 17:
card = deck.pop()
print ("Dealer is dealt " + card_string(card))
dealer.append(card)
print ("The dealer's total is", hand_value(dealer))
dealer[0].state = True
draw_card(dealer,player)
# summary
player_total = hand_value(player)
dealer_total = hand_value(dealer)
print ("\nYour total is", player_total)
print ("The dealer's total is", dealer_total)
if dealer_total > 21:
print ("The dealer went over 21! You win!")
else:
if player_total > dealer_total:
print ("You win!")
elif player_total < dealer_total:
print ("You lost!")
else:
print ("You have a tie!")
if not ask_yesno("\nPlay another round? (y/n) "):
bj_board.close()
break
main()
|
4 | 1 | TA | In #2, you receive an input like a = float(input('side a:')) and then apply a float. Please explain why this process is necessary! | import math
global a
global b
global c
def is_triangle(a, b, c):
longestside = max(a, b, c)
total = a + b + c
remainder = total - longestside
if a> 0 and b> 0 and c>0:
if longestside < remainder:
return True
else:
return False
def entervalues():
a = float(input('side a: '))
print (' Value of a is', a)
b = float(input('side b: '))
print (' Value of a is', b)
c = float(input('side c: '))
print (' Value of a is', c)
if is_triangle(a, b, c) == True :
print ('YES')
else:
print ('NO')
entervalues()
| 5 | 22 | reasoning | If you use the input function, it is converted to a string value.
So I thought that again, using the float function, the numbers can be applied to you too | cs1qa | null | null | null | null | null | Question:
In #2, you receive an input like a = float(input('side a:')) and then apply a float. Please explain why this process is necessary!
Code:
import math
global a
global b
global c
def is_triangle(a, b, c):
longestside = max(a, b, c)
total = a + b + c
remainder = total - longestside
if a> 0 and b> 0 and c>0:
if longestside < remainder:
return True
else:
return False
def entervalues():
a = float(input('side a: '))
print (' Value of a is', a)
b = float(input('side b: '))
print (' Value of a is', b)
c = float(input('side c: '))
print (' Value of a is', c)
if is_triangle(a, b, c) == True :
print ('YES')
else:
print ('NO')
entervalues()
|
2 | 3 | TA | Could you explain the line function of task 4? | from cs1robots import*
load_world('worlds/harvest4.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def line():
while hubo.on_beeper():
hubo.pick_beeper()
for i in range(5):
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
hubo.move()
hubo.turn_left()
for i in range(5):
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
turn_right()
hubo.move()
for i in range(2):
line()
hubo.move()
turn_right()
line()
| 7 | 23 | variable | The line function is a function that passes two lines at a time. As it passes, it continuously collects beepers while standing on the beeper, and moves forward when it is not standing on the beeper. | cs1qa | null | null | null | null | null | Question:
Could you explain the line function of task 4?
Code:
from cs1robots import*
load_world('worlds/harvest4.wld')
hubo=Robot()
hubo.set_trace('blue')
def turn_right():
for i in range(3):
hubo.turn_left()
def line():
while hubo.on_beeper():
hubo.pick_beeper()
for i in range(5):
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
hubo.turn_left()
hubo.move()
hubo.turn_left()
for i in range(5):
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
while hubo.on_beeper():
hubo.pick_beeper()
turn_right()
hubo.move()
for i in range(2):
line()
hubo.move()
turn_right()
line()
|
4 | 2 | TA | What is the unit of x in sin(x) in task3? | import math
sin = math.sin
pi = math.pi
n=int(input('How many steps? '))
for i in range(n):
x = float(i) / (n-1) * 2 * pi
print (sin(x)) | 8 | 9 | variable | Radians
Data type is real | cs1qa | null | null | null | null | null | Question:
What is the unit of x in sin(x) in task3?
Code:
import math
sin = math.sin
pi = math.pi
n=int(input('How many steps? '))
for i in range(n):
x = float(i) / (n-1) * 2 * pi
print (sin(x)) |
6 | 1 | TA | Please explain the count_integers function in task2. | import random
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
i=0
a=[]
while i < trials:
b=[random.randint(lb,ub)]
a=a+b
i=i+1
return a
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
c=sum(num_list)/len(num_list)
return c
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
k=1
n=[]
while k <= max(num_list):
if num_list.count(k)==0:
m=[]
else:
m=[(k,num_list.count(k))]
n=n+m
k=k+1
return n
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
| 30 | 45 | variable | The count_integer function counts how many natural numbers are in a list. | cs1qa | null | null | null | null | null | Question:
Please explain the count_integers function in task2.
Code:
import random
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
i=0
a=[]
while i < trials:
b=[random.randint(lb,ub)]
a=a+b
i=i+1
return a
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
c=sum(num_list)/len(num_list)
return c
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
k=1
n=[]
while k <= max(num_list):
if num_list.count(k)==0:
m=[]
else:
m=[(k,num_list.count(k))]
n=n+m
k=k+1
return n
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
|
1 | 1 | TA | In Task 2
while my_robot.on_beeper():
my_robot.pick_beeper()
```
while my_robot.on_beeper():
my_robot.pick_beeper()
```
You used the while statement twice.
Is there a reason...? | from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
#load_world( "worlds/trash2.wld" )
my_robot = Robot()
my_robot.set_trace('red')
def turn_right():
for i in range(3):
my_robot.turn_left()
def turn():
for i in range(2):
my_robot.turn_left()
def go():
while my_robot.front_is_clear():
while my_robot.on_beeper():
my_robot.pick_beeper()
my_robot.move()
while my_robot.on_beeper():
my_robot.pick_beeper()
turn()
while my_robot.front_is_clear():
my_robot.move()
turn_right()
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
turn()
my_robot.move()
my_robot.turn_left()
go() | 15 | 31 | reasoning | It seems to be to solve the last 10 beeper. | cs1qa | null | null | null | null | null | Question:
In Task 2
while my_robot.on_beeper():
my_robot.pick_beeper()
```
while my_robot.on_beeper():
my_robot.pick_beeper()
```
You used the while statement twice.
Is there a reason...?
Code:
from cs1robots import *
# Your code must work for all world files below.
load_world( "worlds/trash1.wld" )
#load_world( "worlds/trash2.wld" )
my_robot = Robot()
my_robot.set_trace('red')
def turn_right():
for i in range(3):
my_robot.turn_left()
def turn():
for i in range(2):
my_robot.turn_left()
def go():
while my_robot.front_is_clear():
while my_robot.on_beeper():
my_robot.pick_beeper()
my_robot.move()
while my_robot.on_beeper():
my_robot.pick_beeper()
turn()
while my_robot.front_is_clear():
my_robot.move()
turn_right()
my_robot.move()
while my_robot.carries_beepers():
my_robot.drop_beeper()
turn()
my_robot.move()
my_robot.turn_left()
go() |
6 | 1 | TA | Please explain the count_integers function in task2. | import random
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
i=0
a=[]
while i < trials:
b=[random.randint(lb,ub)]
a=a+b
i=i+1
return a
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
c=sum(num_list)/len(num_list)
return c
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
k=1
n=[]
while k <= max(num_list):
if num_list.count(k)==0:
m=[]
else:
m=[(k,num_list.count(k))]
n=n+m
k=k+1
return n
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
| 30 | 45 | variable | The count_integer function counts how many natural numbers are in a list. | cs1qa | null | null | null | null | null | Question:
Please explain the count_integers function in task2.
Code:
import random
def drawing_integers(lb, ub, trials):
"""
Make a list of the integers
:param lb: the lower bound of the integers
:param ub: the upper bound of the integers
:param trials: the number of trials
:return: an integers list. Ex) [1, 4, 3, 5, 2]
"""
i=0
a=[]
while i < trials:
b=[random.randint(lb,ub)]
a=a+b
i=i+1
return a
def average_integers(num_list):
"""
Compute the average of the integers in the num_list
:param num_list: input list
:return: average value of the list
"""
c=sum(num_list)/len(num_list)
return c
def count_integers(num_list):
"""
Count the integers in the num_list
:param num_list: input list
:return: A list of tuples that consist of the integer and its frequency
"""
k=1
n=[]
while k <= max(num_list):
if num_list.count(k)==0:
m=[]
else:
m=[(k,num_list.count(k))]
n=n+m
k=k+1
return n
# Run the program
list1 = drawing_integers(1, 6, 20)
print(list1)
print(average_integers(list1))
print(count_integers(list1))
print()
list2 = drawing_integers(5, 12, 15)
print(list2)
print(average_integers(list2))
print(count_integers(list2))
|
4 | 0 | TA | In task1, Can you tell me the role of variable j? | from cs1robots import *
load_world("worlds/add34.wld")
hubo= Robot(street=1, avenue=1)
i = 0
def reverse():
for i in range(2):
hubo.turn_left()
def turn_right():
for i in range(3):
hubo.turn_left()
def pick_counter():
global i
i = 0
while hubo.on_beeper():
hubo.pick_beeper()
i = i+1
j = 100000000
k = 0
def add():
global i, j, k
k = i*j + k
j=j/10
print(k)
def move():
global k,j
while hubo.front_is_clear():
hubo.move()
pick_counter()
add()
reverse()
while hubo.front_is_clear():
hubo.move()
turn_right()
hubo.move()
turn_right()
j = 100000000
while hubo.front_is_clear():
hubo.move()
pick_counter()
add()
move()
turn_right()
hubo.move()
turn_right()
while k >0 :
for i in range(int(k%10)):
hubo.drop_beeper()
hubo.move()
k = k//10
| 18 | 25 | variable | J is used to multiply the counted number of beepers, so that they can be stored in proper decimal format. | cs1qa | null | null | null | null | null | Question:
In task1, Can you tell me the role of variable j?
Code:
from cs1robots import *
load_world("worlds/add34.wld")
hubo= Robot(street=1, avenue=1)
i = 0
def reverse():
for i in range(2):
hubo.turn_left()
def turn_right():
for i in range(3):
hubo.turn_left()
def pick_counter():
global i
i = 0
while hubo.on_beeper():
hubo.pick_beeper()
i = i+1
j = 100000000
k = 0
def add():
global i, j, k
k = i*j + k
j=j/10
print(k)
def move():
global k,j
while hubo.front_is_clear():
hubo.move()
pick_counter()
add()
reverse()
while hubo.front_is_clear():
hubo.move()
turn_right()
hubo.move()
turn_right()
j = 100000000
while hubo.front_is_clear():
hubo.move()
pick_counter()
add()
move()
turn_right()
hubo.move()
turn_right()
while k >0 :
for i in range(int(k%10)):
hubo.drop_beeper()
hubo.move()
k = k//10
|
2 | 2 | TA | Why is there an else in line 26 in task3? | from cs1robots import *
import time
#load_world('worlds/hurdles1.wld')
load_world('worlds/hurdles2.wld')
#load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def jump_one_hurdle():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
def turn_right():
for i in range(3):
my_robot.turn_left()
while not my_robot.on_beeper():
while my_robot.front_is_clear():
my_robot.move()
else:
if not my_robot.on_beeper():
jump_one_hurdle() | 25 | 27 | reasoning | Alas, in task 3, since I am not on the beeper and I have to jump if there is a wall in front, I created the following function. | cs1qa | null | null | null | null | null | Question:
Why is there an else in line 26 in task3?
Code:
from cs1robots import *
import time
#load_world('worlds/hurdles1.wld')
load_world('worlds/hurdles2.wld')
#load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def jump_one_hurdle():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
def turn_right():
for i in range(3):
my_robot.turn_left()
while not my_robot.on_beeper():
while my_robot.front_is_clear():
my_robot.move()
else:
if not my_robot.on_beeper():
jump_one_hurdle() |
4 | 0 | TA | What function is summing in task1? | from cs1robots import*
load_world('worlds/add34.wld')
hajun=Robot(avenue=1, street=2, orientation='E')
n=0
def turn_right():
for i in range(3):
hajun.turn_left()
def go_up():
turn_right()
hajun.move()
hajun.turn_left()
hajun.turn_left()
def collect():
n=0
while hajun.on_beeper():
hajun.pick_beeper()
n=n+1
return n
def summing():
a=collect()
hajun.move()
b=collect()
return a+b
while hajun.front_is_clear():
hajun.move()
turn_right()
while(1):
n=summing()
if n==0:
break
if n>9:
for i in range(n-10):
hajun.drop_beeper()
turn_right()
hajun.move()
hajun.drop_beeper()
else:
for i in range(n):
hajun.drop_beeper()
turn_right()
hajun.move()
go_up()
n=0
| 14 | 25 | variable | This is a function that adds up and down in one column. | cs1qa | null | null | null | null | null | Question:
What function is summing in task1?
Code:
from cs1robots import*
load_world('worlds/add34.wld')
hajun=Robot(avenue=1, street=2, orientation='E')
n=0
def turn_right():
for i in range(3):
hajun.turn_left()
def go_up():
turn_right()
hajun.move()
hajun.turn_left()
hajun.turn_left()
def collect():
n=0
while hajun.on_beeper():
hajun.pick_beeper()
n=n+1
return n
def summing():
a=collect()
hajun.move()
b=collect()
return a+b
while hajun.front_is_clear():
hajun.move()
turn_right()
while(1):
n=summing()
if n==0:
break
if n>9:
for i in range(n-10):
hajun.drop_beeper()
turn_right()
hajun.move()
hajun.drop_beeper()
else:
for i in range(n):
hajun.drop_beeper()
turn_right()
hajun.move()
go_up()
n=0
|
1 | 2 | TA | Why can I delete line 17 from Task 3? | from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
load_world('worlds/hurdles2.wld')
# load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def jump_one_hurdle():
if not my_robot.front_is_clear():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
while not my_robot.on_beeper():
if my_robot.front_is_clear():
my_robot.move()
else:
jump_one_hurdle() | 16 | 16 | reasoning | This is because else executed when the if condition in line 28 is false. | cs1qa | null | null | null | null | null | Question:
Why can I delete line 17 from Task 3?
Code:
from cs1robots import *
# Your code should work with any of the world files below.
# TIP: Press Ctrl + '/' (or Cmd + '/' if you are using a Mac)
# to comment out or restore the whole line of the code in the editor.
# load_world('worlds/hurdles1.wld')
load_world('worlds/hurdles2.wld')
# load_world('worlds/hurdles3.wld')
my_robot = Robot()
my_robot.set_trace('blue')
def turn_right():
for i in range(3):
my_robot.turn_left()
def jump_one_hurdle():
if not my_robot.front_is_clear():
my_robot.turn_left()
my_robot.move()
turn_right()
my_robot.move()
turn_right()
my_robot.move()
my_robot.turn_left()
while not my_robot.on_beeper():
if my_robot.front_is_clear():
my_robot.move()
else:
jump_one_hurdle() |
3 | 1 | TA | What is the role of task 2 lap function? | from cs1robots import *
# Your code must work for all world files below.
#load_world( "worlds/trash1.wld" )
load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('red')
def turnaround():
for i in range(2):
hubo.turn_left()
def lap():
turnnumber = 0
while turnnumber <= 2:
if hubo.front_is_clear():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
else:
hubo.turn_left()
turnnumber +=1
def dumpall():
while hubo.carries_beepers():
hubo.drop_beeper()
def done():
lap()
turnaround()
hubo.move()
dumpall()
turnaround()
hubo.move()
hubo.turn_left()
done() | 13 | 22 | variable | In 2, at the same time going straight from the starting point, picking up the beeper as it is, and then turning it when it touches the wall. At this time, the number of turns is limited to two so that it returns to the origin.
Using lap, done was a function that wrote down the process one by one so that the robot returned to the origin discards the trash above it! | cs1qa | null | null | null | null | null | Question:
What is the role of task 2 lap function?
Code:
from cs1robots import *
# Your code must work for all world files below.
#load_world( "worlds/trash1.wld" )
load_world( "worlds/trash2.wld" )
hubo = Robot()
hubo.set_trace('red')
def turnaround():
for i in range(2):
hubo.turn_left()
def lap():
turnnumber = 0
while turnnumber <= 2:
if hubo.front_is_clear():
while hubo.on_beeper():
hubo.pick_beeper()
hubo.move()
else:
hubo.turn_left()
turnnumber +=1
def dumpall():
while hubo.carries_beepers():
hubo.drop_beeper()
def done():
lap()
turnaround()
hubo.move()
dumpall()
turnaround()
hubo.move()
hubo.turn_left()
done() |
1 | 0 | TA | What is turn_right()? | from cs1robots import *
create_world()
hubo = Robot()
hubo.set_trace('blue')
def go_straight():
for i in range(9):
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def zigzag():
hubo.turn_left()
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
def zigzag_ready():
zigzag()
hubo.turn_left()
hubo.move()
for i in range(4):
zigzag_ready()
zigzag() | 9 | 12 | variable | It is a function that rotates to the right, but it does not have a function to rotate to the right, so it is a function made with three left turns! | cs1qa | null | null | null | null | null | Question:
What is turn_right()?
Code:
from cs1robots import *
create_world()
hubo = Robot()
hubo.set_trace('blue')
def go_straight():
for i in range(9):
hubo.move()
def turn_right():
for i in range(3):
hubo.turn_left()
def zigzag():
hubo.turn_left()
go_straight()
turn_right()
hubo.move()
turn_right()
go_straight()
def zigzag_ready():
zigzag()
hubo.turn_left()
hubo.move()
for i in range(4):
zigzag_ready()
zigzag() |
6 | 2 | TA | What is the case for num1 and num2 that return False when is_valid? | from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
random.shuffle(cards) # 3-2-1. shuffle the card list
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 in correct_list or num2 in correct_list or num1==num2 or num1<0 or num1>23 or num2<0 or num2>23:
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if cards[num1][1] != cards[num2][1]:
correct_list.remove(num1)
correct_list.remove(num2)
print_cards()
return False
return True
initialize()
correct_list = list(range(24))
print_cards()
correct_list = []
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while correct_list != list(range(24)): # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
########################################################################### | 65 | 65 | variable | If the number of cards already matched, if the two numbers are the same, if it exceeds the range of 0 to 23 | cs1qa | null | null | null | null | null | Question:
What is the case for num1 and num2 that return False when is_valid?
Code:
from cs1graphics import *
import time
import random
canvas = Canvas(640, 580)
canvas.setTitle("Memento")
path = "./images/"
names = ("Dohoo.jpg", "Jeongmin.jpg", "Jinyeong.jpg",
"Minsuk.jpg", "Sangjae.jpg", "Sungeun.jpg")
cards = []
num_pads = []
tries = 1
def initialize():
# initialize cards
for i in range(6):
for k in range(4):
img = Image(path+names[i])
temp_tuple = (img, names[i])
cards.append(temp_tuple)
for i in range(24):
card = Layer()
rect = Rectangle(90, 120, Point(0, 0))
text = Text(str(i), 18, Point(0, 0))
card.add(rect)
card.add(text)
num_pads.append(card)
################################################################
random.shuffle(cards) # 3-2-1. shuffle the card list
################################################################
def print_cards():
canvas.clear()
w = 0
h = 0
i_w = 70
i_h = 90
for i in range(len(num_pads)):
################################################################
if i in correct_list: # 3-2-2. rewrite the condition for visualization.
################################################################
cards[i][0].moveTo(i_w + w, i_h+h)
canvas.add(cards[i][0])
else:
num_pads[i].moveTo(i_w + w, i_h+h)
canvas.add(num_pads[i])
w += 100
if w % 600 == 0:
w = 0
h += 130
time.sleep(1)
def is_valid(num1, num2):
###########################################################################
# 3-1-1. Check if any of two numbers exists in the current correct list,
# two numbers are the same,
# or both of the numbers are within a valid range.
# Return Boolean value according to the result.
###########################################################################
if num1 in correct_list or num2 in correct_list or num1==num2 or num1<0 or num1>23 or num2<0 or num2>23:
return False
else:
return True
def check(num1, num2):
###########################################################################
# 3-1-2. At first, visualize the screen including the two cards
# (num1-th card and num2-th card).
# If two pictures of the two cards are same
# put two numbers into the correct list.
# If not, re-visualize the original screen.
# Return Boolean value according to the result.
###########################################################################
correct_list.append(num1)
correct_list.append(num2)
print_cards()
if cards[num1][1] != cards[num2][1]:
correct_list.remove(num1)
correct_list.remove(num2)
print_cards()
return False
return True
initialize()
correct_list = list(range(24))
print_cards()
correct_list = []
print_cards()
print("### Welcome to the Python Memento game!!! ###")
###############################################################################
while correct_list != list(range(24)): # 3-2-3. Rewrite the condition for termination
###############################################################################
###########################################################################
# 3-2-4. Print the number of tries and the corrected pairs
print(str(tries) + "th try. You got " + str(len(correct_list)//2) + " pairs.")
###########################################################################
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if not is_valid(num1, num2):
continue
if check(num1, num2):
print("Correct!")
else:
print("Wrong!")
###########################################################################
# 3-2-5. Update number of tries (global variable, tries)
tries += 1
########################################################################### |
4 | 1 | TA | Why should we apply float() after receiving input() in Task 2? | global a, b, c
def is_triangle(a, b, c):
# print('Value of a is', a)
# print('Value of b is', b)
# print('Value of c is', c)
if a>=b:
if a>=c:
if a>=(b+c):
return False
else:
return True
else:
if c>=(a+b):
return False
else:
return True
else:
if b>=c:
if b>=(a+c):
return False
else:
return True
else:
if c>=(a+b):
return False
else:
return True
a = float(input('Side a: '))
b = float(input('Side b: '))
c = float(input('Side c: '))
if is_triangle(a, b, c)==True:
print('Yes')
else:
print('No') | 2 | 33 | reasoning | When it receives input, it recognizes the variable as a string and recognizes it as a number! | cs1qa | null | null | null | null | null | Question:
Why should we apply float() after receiving input() in Task 2?
Code:
global a, b, c
def is_triangle(a, b, c):
# print('Value of a is', a)
# print('Value of b is', b)
# print('Value of c is', c)
if a>=b:
if a>=c:
if a>=(b+c):
return False
else:
return True
else:
if c>=(a+b):
return False
else:
return True
else:
if b>=c:
if b>=(a+c):
return False
else:
return True
else:
if c>=(a+b):
return False
else:
return True
a = float(input('Side a: '))
b = float(input('Side b: '))
c = float(input('Side c: '))
if is_triangle(a, b, c)==True:
print('Yes')
else:
print('No') |
3 | 3 | TA | How did you separate the windows and walls in task4?? | from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain1.wld')
# load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
def turn_around() :
hubo.turn_left()
hubo.turn_left()
def turn_right() :
turn_around()
hubo.turn_left()
hubo.move()
hubo.drop_beeper()
turn_right()
hubo.move()
m=0
k=0
while(not(hubo.on_beeper())):
m=k
k=0
if(hubo.right_is_clear()):
k=1
if(k==0 and m==1):
turn_around()
hubo.move()
hubo.drop_beeper()
turn_around()
hubo.move()
if(k==1 and m==1):
turn_around()
hubo.move()
hubo.turn_left()
m=0
k=0
if(not(hubo.front_is_clear())):
hubo.turn_left()
hubo.move()
# Now close all the windows in the house! | 23 | 37 | code_explain | If the right side is empty, it is basically a window.
If the right side is empty twice in a row, I used a right turn, not a window.
Whether the right side is empty in the previous column or m, and whether the right side is empty in this column is indicated through k | cs1qa | null | null | null | null | null | Question:
How did you separate the windows and walls in task4??
Code:
from cs1robots import *
# Your code must work for both of the worlds below.
load_world('worlds/rain1.wld')
# load_world('worlds/rain2.wld')
# Initialize your robot at the door of the house.
hubo = Robot(beepers=100, avenue=2, street=6, orientation='E')
hubo.set_trace('blue')
def turn_around() :
hubo.turn_left()
hubo.turn_left()
def turn_right() :
turn_around()
hubo.turn_left()
hubo.move()
hubo.drop_beeper()
turn_right()
hubo.move()
m=0
k=0
while(not(hubo.on_beeper())):
m=k
k=0
if(hubo.right_is_clear()):
k=1
if(k==0 and m==1):
turn_around()
hubo.move()
hubo.drop_beeper()
turn_around()
hubo.move()
if(k==1 and m==1):
turn_around()
hubo.move()
hubo.turn_left()
m=0
k=0
if(not(hubo.front_is_clear())):
hubo.turn_left()
hubo.move()
# Now close all the windows in the house! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.