Exemplo n.º 1
0
def gardenCost ():
    soilCost = validateInt("What does the soil cost?: ")
    seedCost = validateInt("What do the flower seeds cost?: ")
    fenceCost = validateInt("What does the fence cost?: ")

    totalCost = soilCost + seedCost + fenceCost

    print("The garden's total cost is: {}\n".format(totalCost))
Exemplo n.º 2
0
def extremes():
    listLength = validateInt("Enter the length of your number list:")

    print("Enter {} numbers for your list:\n".format(listLength))
    min = max = validateInt("")

    for i in range(listLength - 1):
        newValue = validateInt("")
        if newValue > max:
            max = newValue
        elif newValue < min:
            min = newValue

    print("\nMIN: {}\nMAX: {}\n".format(min, max))
Exemplo n.º 3
0
def guessNum():

    trueNum = validateInt("Pick a number for another user to guess:")
    guessedNum = validateInt("Guess a number:")
    count = 0

    while (guessedNum != trueNum):
        if (guessedNum > trueNum):
            guessedNum = validateInt("Your guess was too high. Try again:")
        elif (guessedNum < trueNum):
            guessedNum = validateInt("Your guess was too low. Try again:")
        count += 1

    print(
        "You guessed it! It took you {} tries to get the correct answer of {}.\n"
        .format(count, trueNum))
Exemplo n.º 4
0
def calculateAverage(n):
    sum = 0
    print("Please enter {} integers:\n".format(n))
    for x in range(0, n):
        sum += validateInt("Integer {}: ".format(x + 1))

    average = sum / n
    print("\nThe average of numbers entered = {}".format(average))
Exemplo n.º 5
0
def convertTemperature():
    celcius = validateInt("Please enter a temperature in celsius: ")

    fahrenheit = (9.0 / 5.0) * celcius + 32

    print(
        "The equivalent temperature to {} celcius is {} fahrenheit.\n".format(
            celcius, fahrenheit))
Exemplo n.º 6
0
def sortList():
    myList = heap([])

    print("This program sorts a list of integers using a heap abstraction.\n")
    length = validateInt("How long would you like your list to be?: ")
    print("Please enter {} integers in any order to fill your list:".format(
        length))

    for i in range(length):
        myList.appendList(validateInt(""))

    print("The order of your list as entered:")
    myList.printList()

    print("\nYour sorted list:")
    myList.sortHeap()
    myList.printList()
Exemplo n.º 7
0
def calculateFall():

    print("Calculating the distance an object fell...")
    fallTime = validateInt("How many seconds was the object falling?: ")

    print("The object traveled {:0.2f} meters.".format(fallDistance(fallTime)))
Exemplo n.º 8
0
def calcHailstone():
    steps = hailstone(
        validateInt("Please enter a number to begin the hailstone sequence: "))
    print("The hailstone sequence took {} steps".format(steps))