コード例 #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))
コード例 #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))
コード例 #3
0
ファイル: numGuess.py プロジェクト: aDerringer/pyCS161
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))
コード例 #4
0
ファイル: average.py プロジェクト: aDerringer/pyCS161
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))
コード例 #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))
コード例 #6
0
ファイル: smallSort.py プロジェクト: aDerringer/pyCS161
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()
コード例 #7
0
ファイル: fallDistance.py プロジェクト: aDerringer/pyCS161
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)))
コード例 #8
0
ファイル: hailstone.py プロジェクト: aDerringer/pyCS161
def calcHailstone():
    steps = hailstone(
        validateInt("Please enter a number to begin the hailstone sequence: "))
    print("The hailstone sequence took {} steps".format(steps))