Пример #1
0
def run_test(control_dist):
    test = calculate.calc(control_dist)
    if test == -1:
        return -1
    start = test[0].format("MM.DD.YYYY HH:mm")
    finish = test[1].format("MM.DD.YYYY HH:mm")
    return [start, finish]
Пример #2
0
def move():
    # Move the asteroid according to the calculation result
    # Result will be a 2 dimensional tuple (2 inner-tuples in 1 outer-tuple)
    # ย้ายดาวเคราะห์น้อย ตามผลการคำนวณ
    # ผลลัพธ์จะเป็น 2 มิติ ทัพเพิล (2 ทัพเพิลภายใน ใน 1 ทัพเพิลด้านนอก)
    result = calculate.calc()
    # result คือ 1 ทัพเพิลด้านนอก
    # ใน result มี 2 ทัพเพิลภายใน (ตำแหน่งของดาวเคราะห์ & ความเร็ว)
    position = result[0]
    velocity = result[1]
    label_star.place(x=position[0], y=position[1])

    # Show the velocity
    # แสดงความเร็ว
    show_velocity(velocity[0], velocity[1])

    # ตรวจสอบว่า ดาวเคราะห์น้อยอยู่นอกหน้าต่าง หรือไม่
    if (position[0] < 400 and position[1] < 400 and position[0] >= 0
            and position[1] >= 0):
        # NO = call “move” again (ดาวเคราะห์น้อยอยู่ในหน้าต่าง = เรียก "move" อีกครั้ง)
        root.after(10, move)
    else:
        # YES = Stop Loop (ดาวเคราะห์น้อยอยู่นอกหน้าต่าง = หยุดวนซ้ำ)
        # หากเราไม่เรียกใช้ฟังก์ชัน "move"  วนซ้ำจะหยุดโดยอัตโนมัติ

        # กลับ ดาวเคราะห์น้อย และ ความเร็ว Entry สู่สถานะดั้งเดิม
        label_star.place(x=0, y=400 / 2)
        show_velocity(10, 15)
Пример #3
0
def calculate():
    """Reads a formula submitted by the user and shows the results
    """
    formula = request.form.get("formula")
    result = calc(formula)
    return render_template("formula_results.html",
                           formula=formula,
                           result=result)
Пример #4
0
def generate_quiz():
    # Hint: Return [x, y, op, result]
    x = randint(2, 10)
    y = randint(1, 10)
    dau = ["+","-","*","/"]
    op = choice(dau)
    z = calc(x, y, op)
    
    result = choice([z-1, z+1])
    return [x, y, op, result]
Пример #5
0
def generate_quiz():
    # Hint: Return [x, y, op, result]
    import random
    import calculate

    x = random.randint(1, 10)
    y = random.randint(1, 10)
    op = random.choice(["+", "-", "*", "/"])
    result = calculate.calc(x, y, op)
    q = random.choice([result - 1, result, result, result, result + 1])
    return [x, y, op, q]
Пример #6
0
def check_answer(x, y, op, result, user_choice):
    z = calc(x, y, op)
    result = choice([z-1, z+1])
    if result == z:
        if user_choice == True:
            return True
        else:
            return False
    else :
        if user_choice == False:
            return True
        else:
            return False
Пример #7
0
def check_answer(x, y, op, q, answer):
    import calculate
    result = calculate.calc(x, y, op)
    if answer == True:
        if q == result:
            return True
        else:
            return False

    if answer == False:
        if q != result:
            return True
        else:
            return False
Пример #8
0
def calc_times():
  """
  Calculates open/close times from miles, using rules
  described at http://www.rusa.org/octime_alg.html.
  Expects one URL-encoded argument, the number of miles.
  """
  app.logger.debug("Got a JSON request");

  dist = request.args.get('dist', 0, type=int)

  tmp = calculate.calc(dist)
  if (tmp == -1):
      return jsonify(result="Distance is more than 10% of the brevet distance.")
  start = tmp[0].format("MM/DD/YYYY HH:mm")
  end = tmp[1].format("MM/DD/YYYY HH:mm")
  returnvalue = "open: {} | close: {}".format(start, end)
  return jsonify(result=returnvalue)
Пример #9
0
from random import *
from calculate import calc
while True:
    a = randint(2, 10)
    b = randint(1, 10)
    op = ["+", "-", "*", "/"]
    pick_op = choice(op)
    z = calc(a, b, pick_op)
    error = choice([-1, 0, 1])
    ans = z + error

    print("{} {} {} = {}".format(a, pick_op, b, ans))
    answer = input("(Y/N)?").lower()
    if error == 0:
        if answer == "y":
            print("bingo!")
        elif answer == "n":
            print("idiot!")
    else:
        if answer == "n":
            print("bingo!")
        elif answer == "y":
            print("idiot!")
Пример #10
0
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import calculate

try:
    driver = webdriver.Chrome()
    driver.get('http://suninjuly.github.io/explicit_wait2.html')
    WebDriverWait(driver, 12).until(EC.text_to_be_present_in_element((By.ID, 'price'), '$100'))
    driver.find_element_by_id('book').click()
    x = driver.find_element_by_id('input_value').text
    driver.find_element_by_id('answer').send_keys(calculate.calc(x))
    driver.find_element_by_id('solve').click()
    time.sleep(5)

finally:
    driver.quit()
from random import randint, choice
from calculate import calc

x = randint(0, 9)
y = randint(0, 9)
list_op = ["+", "-", "*", "/"]
op = choice(list_op)
if op == "/" and y == 0:
    op = choice(list_op)

result = calc(x, y, op)

error = choice([-1, 0, 0, 0, 0, 0, 0, 1])

result_1 = result + error
print("{0} {1} {2} = {3}".format(x, op, y, result_1))

answer_input = input("Y/N ? ").lower()

if result_1 == result:
    if answer_input == "y":
        print("bingo!")
    elif answer_input == "n":
        print("Wrong!!")
if result_1 != result:
    if answer_input == "n":
        print("bingo!")
    elif answer_input == "y":
        print("Wrong!!")
number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
op = ["+", "-", "*", "/"]
from random import *
from calculate import calc
x = choice(number)
y = choice(number)
op_choice = choice(op)

result = calc(x, y, op_choice)

error = choice([-1, 0, 1])
output = result + error
print("{0} {1} {2} = {3}".format(x, op_choice, y, output))
a = input("Your answer is(Y/N)? ").upper()
if error == 0:
    if a == "Y":
        print("Hura")
    elif a == "N":
        print("Wrong")
else:
    if a == "Y":
        print("Wrong")
    elif a == "N":
        print("Hura")