Count numbers in a string (Python VEXCode VR)

Count numbers in a string (Python VEXCode VR)

                    

def go_to(x_loc,y_loc):
    b = x_loc - location.position(X, MM)
    c = y_loc - location.position(Y, MM)
    a = math.sqrt(b**2 + c**2)
    angle = math.asin((math.sin(math.pi/2) * b) / a) / math.pi * 180
    if c < 0:
        drivetrain.turn_to_heading((180 - angle), DEGREES)
    else:
        drivetrain.turn_to_heading(angle, DEGREES)
    drivetrain.drive_for(FORWARD, a, MM)

def count_numbers():
    brain.clear()
    s = '1dfss3sw235fsf7s0k789f567d23jj569'
    count = 0
    temp = list(s)
    for item in temp:
        if(item.isdigit()):
            count = count + 1
        else:
            pass
    
    brain.new_line()
    brain.new_line()
    brain.print("There are", count, "numbers in string!")
    brain.new_line()

    brain.new_line()
  
    for i in range(1):
        cross_num = count -1
        drivetrain.set_drive_velocity(100, PERCENT)
        drivetrain.set_turn_velocity(100, PERCENT)

        wait(0.5, SECONDS)
        pen.set_pen_color(RED)

        
        find_x = -900 + (cross_num % 10) * 200
        find_y = -900
        if cross_num > 9 and cross_num < 90:
            while cross_num > 9:
                cross_num = cross_num/10
            find_y = find_y + (math.floor(cross_num) * 200)
        if cross_num >= 90:
            find_y = 900

        go_to(find_x,find_y)
        drivetrain.turn_to_heading(90,DEGREES)
        pen.move(DOWN)
        drivetrain.drive_for(REVERSE,40,MM)     
        drivetrain.drive_for(FORWARD,75,MM)     
        pen.move(UP)

    go_to(0,0)

vr_thread(count_numbers())

                

Leave a Reply

Your email address will not be published. Required fields are marked *

LinkedIn
Share
× How can I help you?