I'm in a computer programming course on Florida Virtual School, and I'm stressing out over our current assignment, because it seems like it should be easy.
The point of the assignment is to write a program to count how many times the Scribbler robot stalls and then print the results on the screen, but I can't seem to count it.
Here's my code:

from myro import*
init("simulator")

def pressC():
    key = "x"
    while key != "c":
        key = raw_input("Enter c to continue: ")

def stopStalling():
    stallIndication = getStall()
    if(stallIndication == 1):
        backward(1,1)
    else:
        forward(1,1)

def numStalls(stallNumber):
    stallNum = 0
    for count in range(stallIndication):
        result = getStall()
        if(result == 1):
            stallNum = stallNum + 1
    return stallNum
 
def main():
    pressC()
    senses()
    while timeRemaining(30):
        stopStalling()
    numStalls(stallNumber)
    stop()
main()

Anything helpful would be greatly appreciated! It's my senior year, and I'm just ready to finish this class, haha. Thanks in advance!

I did this course just last year. :) Here is the code I used. You will have to run this program in the CMD as it references some code only applicable to Windows command prompt.

#THIS PROGRAM WILL ONLY WORK IF RAN IN THE CMD! You can accomplish this by simply double clicking on the program's icon.
#The purpose of this program is to have the robot appropriately react when it stalls.

# Programmer: Scott L.
# Date: 11/07/2011
# File: Countstalls.py

import os
from myro import *
init("simulator")

def pressC():
    key = "x"
    while key != "c":
        key = raw_input("Enter c to continue: ")

def main():
    pressC()
    stall = 1
    while timeRemaining(120):
        stallStatus = getStall()
        if(stallStatus == 1):
            os.system("CLS") #Clears the terminal of any characters
            print ("Number of Stalls =" + str(stall)) #Prints the total number of stalls
            stall = stall + 1
            backward(1,1)
            turnLeft(1,1)
        else:
            forward(1,1)
    return stall
    stop()
    print
    raw_input("Press the Enter Key to Exit")
    
main()

Wow, thank you so much, haha. Do you mind if I ask you a few questions about it?

What exactly was the purpose of importing os, and why did you initialize stall as 1?

I imported the OS library because I use this command

os.system("CLS") #Clears the terminal of any characters

This clears what is currently printed in the terminal and immediate replaces it with the new value for the "stall" variable. I did this so that it doesn't make a big long list that you have to scroll through to read. I set the "stall" variable to 1 because when it hits a wall it will print the current value of "stall" then add 1 to it so that next time it prints stall it will be what it was previously set to. Get it?

This article has been dead for over six months. Start a new discussion instead.