Exemple #1
0
def main():
  myTimer = timer.begin_timer()
  stringer.show_welcome(NAME)
  should_Exit = False
  yearly_interest_rate = monthly_investment = Decimal("0.00")
  years = 0
  while not should_Exit:
    print()
    # get validated input from the user
    monthly_investment = Decimal(validation.get_float("Enter monthly investment:\t", 1000))
    yearly_interest_rate = Decimal(validation.get_float("Enter yearly interest rate:\t", 15))
    years = validation.get_int("Enter number of years:\t\t", 50)

    future_value, total_investment = calculate_future_value(monthly_investment, yearly_interest_rate, years)
    display_investment_results(monthly_investment, years, total_investment, future_value)

    if years != 20:
      choice = input("See results for 20 year investment? (y/n): ")
      if choice.lower() == "y":
        # call using default value for years
        future_value, total_investment = calculate_future_value(monthly_investment, yearly_interest_rate)
        # call function using named args in alternative order
        display_investment_results(monthly_investment, totalInv=total_investment, resulting_value=future_value, years=20)

    choice = input("Try Future Value program again? (y/n): ")
    if choice.lower() != "y":
      should_Exit = True

  # end while loop
  timer.stop_timer(myTimer)
  print("Bye!")
Exemple #2
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    should_Exit = False
    converted_temp = 0.0
    while not should_Exit:
        print()
        # get input from the user
        scale = input("Enter current scale \'F\' or \'C\':\t")
        if scale.lower() != 'c' and scale.lower() != 'f':
            print("ERROR, invalid scale. Please try again.")
            continue
        try:
            temperature = float(input("Enter current temperature:\t"))
        except ValueError:
            print("ERROR, temperature should be a number. Please try again.")
            continue

        if scale.lower() == 'f':
            converted_temp = round(temp.to_celsius(temperature), 2)
            print("Degrees Celsisus = ", end=" ")
        else:
            converted_temp = round(temp.to_fahrenheit(temperature), 2)
            print("Degrees Fahrenheit = ", end=" ")

        print(str(converted_temp))

        choice = input("Go again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    display_menu()
    print()

    while True:
        print()
        file = input("Path to .txt file? ")
        print()
        try:
            if file == "exit":
                break
            else:
                words = get_words(file)  # get a list of words from the file
                word_count = count_words(words)  # create a dictionary
                display_word_count(word_count)

        except Exception as e:
            print("There was an Error processing your file.", e)
            continue

    # end while loop

    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    print()
    # tuple of product objects demonstrating polymorphism
    products = (Product("Heavy hammer", 12.99,
                        62), Product("Light nails", 5.06,
                                     0), Movie("Blade Runner", 29.99, 0, 1984),
                Book("Moby Dick", 19.99, 0,
                     "Herman Melville"), Product("Medium tape", 7.24, 0))
    show_products(products)

    while True:
        print()

        try:
            number = val.get_int("Enter Product number: ", len(products), 0)
            product = products[number - 1]
            show_product(product)

        except Exception as e:
            print("There was an Error processing your product.", e)
            break

        choice = input("View another? (y/n): ").lower()
        if choice != "y":
            break

    # end while loop

    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    converted_temp = 0.0
    while True:
        converter = Temp()  # create instance of Temp class obj
        print()
        # get input from the user
        scale = input("Enter current scale \'F\' or \'C\':\t")
        if scale.lower() != 'c' and scale.lower() != 'f':
            print("ERROR, invalid scale. Please try again.")
            continue
        try:
            temperature = float(input("Enter current temperature:\t"))
        except ValueError:
            print("ERROR, temperature should be a number. Please try again.")
            continue

        if scale.lower() == 'f':
            converted_temp = converter.getCelsius(temperature)
            print("Degrees Celsisus = ", end=" ")
        else:
            converted_temp = converter.getFahrenheit(temperature)
            print("Degrees Fahrenheit = ", end=" ")

        print(str(converted_temp))

        choice = input("Go again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    display_warning()
    print()
    display_menu()
    while True:
        print()
        command = input("\nBy Your Command...\t")
        command = command.rstrip()
        if command.lower() == "fac":
            my_factorial()
        elif command.lower() == "fib":
            my_fib()
        elif command.lower() == "tow":
            my_towers()
        elif command.lower() == "help":
            display_menu()
        elif command.lower() == "exit":
            break
        else:
            print("\""+ str(command) + "\" is not a valid selection. Please try again.\n")

    # end while loop
        
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    should_Exit = False

    while not should_Exit:
        print()

        # get input from the user
        length = float(input("Enter Rectangle length:\t"))
        width = float(input("Enter Rectangle width:\t"))

        # calculate
        area = round(length * width, 2)
        perimiter = round(length * 2 + width * 2, 2)

        print()
        print("Area =\t\t", area)
        print("Perimiter =\t", perimiter)
        print()

        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #8
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    num_Loops = 0
    should_Exit = False
    while not should_Exit:
        print()
        # get input from the user
        try:
            num_Loops = int(input("Enter number of times to loop: "))
        except ValueError:
            print ("ERROR, number of times to loop should be an integer. Please try again.")
            continue
        if num_Loops <= 0.0:
            print ("Number of times to loop must be greater than zero! Please try again.")
            continue
        elif num_Loops > 10.0:
            print (str(num_Loops) + " times to loop is too ambitious! Automatically re-setting to 10.")
            num_Loops = 10
        # loop specified number of times
        total = 0
        final = num_Loops - 1
        print()
        print("Looping through range from 0 to " + str(final))
        for i in range(num_Loops):
            total += i
            print(i, end = " ")
        print()
        print("Looping backwards through range from " + str(num_Loops) + " down to 1") 
        for i in range(num_Loops, 0, -1):
            print(i, end = " ")
        print()
        print("Looping through range from 0 to " + str(num_Loops) + " by 2s") 
        for i in range(2, num_Loops+1, 2):
            print(i, end = " ")
        print()
        print("The sum of the numbers from 0 to " + str(final) + " is: " + str(total))         
        print()
        choice = input("Want to know how much a $10,000 investment at 5% interest will be worth in " + str(num_Loops) + " years? (y/n): ")
        if choice.lower() != "y":
            break
        investment = 10000
        for i in range(num_Loops):
            yearly_interest = investment * .05
            investment = investment + yearly_interest
            investment = round(investment, 2)
        print("After " + str(num_Loops) + " years, your $10,000 investment is now worth $" + str(investment) + "!!!")
 
        choice = input("Try loopy program again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
        # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #9
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    miles_driven = gallons_used = cost_per_gallon = 0
    should_Exit = False
    while not should_Exit:
        print()
        #   get input from the user
        try:
            miles_driven = float(input("Enter miles drivens:\t\t"))
            gallons_used = float(input("Enter gallons of gas used:\t"))
            cost_per_gallon = float(input("Enter cost per gallon:\t\t"))
        except ValueError:
            print(
                "ERROR, ALL values entered must belong to the set containing only numbers. Please try again."
            )
            continue

        if miles_driven <= 0.0:
            print("Miles driven must be greater than zero! Please try again.")
            continue
        elif gallons_used <= 0.0:
            print("Gallons used must be greater than zero! Please try again.")
            continue
        elif cost_per_gallon <= 0.0:
            print(
                "Cost per gallon must be greater than zero! Please try again.")
            continue

    #   calculate miles per gallon
        mpg = miles_driven / gallons_used
        mpg = round(mpg, 2)

        #   calculate total cost of gas
        total_cost = round(gallons_used * cost_per_gallon, 2)

        #   calculate cost per mile
        cost_per_mile = round(total_cost / miles_driven, 2)

        #   format and display the result
        print()
        print("Miles Per Gallon:\t\t" + str(mpg))
        print("Total gas cost:\t\t\t" + str(total_cost))
        print("Cost per mile:\t\t\t" + str(cost_per_mile))
        print()
        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
    #   end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    should_Exit = False
    converted_temp = 0.0
    while not should_Exit:
        play_game()

        choice = input("Go again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #11
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    # create tuple of Product objects
    products = (Book("Moby Dick", 19.99, 0, "Herman Melville"),
                Product("Heavy hammer", 9.95, 13),
                Movie("Blade Runner", 29.99, 0, 1984))
    print()
    print("This program creates 3 objects of different types and, uses polymorphism to display data on each object.")
    print()
    show_products(products)
   
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    display_rules()
    should_Exit = False

    while not should_Exit:
        print()
        play_game()

        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
    #   end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #13
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    print()
    print("Play the HANGMAN game")

    while True:
        print()
        play_game()
        print()

        choice = input("Try \'" + NAME + "\' program again? (y/n): ")
        if choice.lower() != "y":
            break

    # end while loop
    timer.stop_timer(myTimer)
Exemple #14
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    while True:
        print()
        show_ordinal_values()
        demonstrate_string_indices_and_slices()
        demonstrate_string_searches()
        play_with_strings()

        choice = input("Try \'" + NAME + "\' program again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    catalog = {
        "Moby Dick": {
            "author": "Herman Melville",
            "pubYear": "1851"
        },
        "The Hobbit": {
            "author": "J. R. R. Tolkien",
            "pubYear": "1937"
        }
    }

    display_menu()

    while True:
        print()
        command = input("By your command: ")
        print()
        try:
            command = command.lower().strip()
            if command == "show":
                show_book(catalog)
            elif command == "add" or command == "eidt":
                add_edit_book(catalog, mode=command)
            elif command == "del":
                delete_book(catalog)
            elif command == "h" or command == "help":
                display_menu()
            elif command == "exit":
                break
            else:
                print(command + " is not a valid command. Please try again.")
                continue

        except Exception as e:
            print("There was an Error processing your command: ", e)
            continue

    # end while loop

    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #16
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    display_help()
    
    while True:
        scores = []
        response = get_scores(scores)
        if response != "x":
            display_results(scores)
        print()
    

        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            break
        # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    while True:
        print()
        full_name = get_full_name()

        password = get_password()

        first_name = get_first_name(full_name)

        print("Hi " + first_name + " thanks for creating an account.")

        choice = input("Try \'" + NAME + "\' program again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #18
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    random_list = [0] * 11
    fixed_tuple = (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)
    print("TUPLE DATA: ", fixed_tuple)
    get_meta_data(fixed_tuple)
    print()

    while True:
        generate_random_list(random_list)
        print()
        print("RANDOM DATA: ", random_list)
        get_meta_data(random_list)
        print()

        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    print()

    while True:
        print()

        try:
            number = val.get_int("Enter number of dice to roll: ", 10,
                                 0)  # use validation module to set max 10 dice

            #create Dice object to hold the dice
            dice = Dice()
            for i in range(number):
                die = Die()
                dice.addDie(die)

            #roll dem bones!
            dice.rollAll()

            print("YOUR ROLL: ")
            # use itertor from class Dice
            for die in dice:
                print(die.getImage())
            print()

        except Exception as e:
            print("There was an Error processing your roll.", e)
            break

        choice = input("Roll again? (y/n): ").lower()
        if choice != "y":
            break

    # end while loop

    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    while True:

        arrival_date = get_arrival_date()
        departure_date = get_departure_date(arrival_date)
        print()

        # calculate nights and cost
        rate_message = ""
        rate = RATE
        if arrival_date.month == 8:  #August is high season
            rate_message = "(High Season Rates Apply)"
            rate = RATE * 1.25
        total_nights = (departure_date - arrival_date).days
        total_cost = total_nights * rate

        #display formatted results
        date_format = "%B %d, %Y"
        result = locale.setlocale(locale.LC_ALL, "")
        if result == "C":
            locale.setlocale(locale.LC_ALL, "en_US")

        print("Arrival:           ", arrival_date.strftime(date_format))
        print("Departure:         ", departure_date.strftime(date_format))
        print("Nightly rate:      ", locale.currency(rate), rate_message)
        print("Nights total:      ", total_nights)
        print("Price total:       ", locale.currency(total_cost))
        print()

        choice = input("Try \'" + NAME + "\' program again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)

    countries = {"CA": "Canada", "US": "United States", "MX": "Mexico"}

    display_menu()

    while True:
        print()
        command = input("By your command: ")
        print()
        try:
            command = command.lower().strip()
            if command == "view":
                view(countries)
            elif command == "add":
                add(countries)
            elif command == "del":
                delete(countries)
            elif command == "h" or command == "help":
                display_menu()
            elif command == "exit":
                break
            else:
                print(command + " is not a valid command. Please try again.")
                continue

        except Exception as e:
            print("There was an Error processing your command: ", e)
            continue

    # end while loop

    timer.stop_timer(myTimer)
    print("Bye!")
def main():
  myTimer = timer.begin_timer()
  stringer.show_welcome(NAME)
  movies_list = [[]]#initialize empty list with correct structure
  movies_list.pop()#remove empty element
  save_mode = ""
  file_to_find = ""

  pick_mode()#show user the types of files we can save the movies in

  while True:
    save_mode = input("\nMode?\t")
    save_mode = save_mode.rstrip()
    if save_mode.lower() == "txt":
      print("From main(), txt file selected by user.")
      break
    elif save_mode.lower() == "csv":
      print("From main(), csv file selected by user.")
      break
    elif save_mode.lower() == "bin":
      print("From main(), bin file selected by user.")
      break
    else:
      print("\""+ str(save_mode) + "\" is not a valid selection. Please try again.\n")

  # let's see if the MOVIE_FILE exists or not
  file_to_find = get_save_file(save_mode)
  if os.path.isfile(file_to_find):
    # the MOVIE_FILE is where we expected it
    read_movies_file(movies_list, save_mode)
  else:
    # the file does not exist where it is expected
    # initialize data and try to create the file
    initialize_movie_data(movies_list, save_mode)

  display_menu()
  try:
    while True:
      command = input("\nBy Your Command...\t")
      command = command.rstrip()
      if command.lower() == "list":
        print_movie_list(movies_list)
      elif command.lower() == "add":
        add_movie_to_list(movies_list, save_mode)
      elif command.lower() == "del":
        delete_movie_from_list(movies_list, save_mode)
      elif command.lower() == "help":
        display_menu()
      elif command.lower() == "cnt":
        display_count(movies_list)
      elif command.lower() == "test":
        run_tests()
      elif command.lower() == "exit":
        break
      else:
        print("\""+ str(command) + "\" is not a valid selection. Please try again.\n")
   # end while loop
  except ValueError as e:
    print("ValueError:", e)
  finally:
    timer.stop_timer(myTimer)
    print("Bye!")
Exemple #23
0
def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    should_Exit = False

    while not should_Exit:
        new_invoice_total = invoice_total = discount_percent = discount_amount = 0
        customer_type = "unknown_type"

        # get customer_type from the user
        display_customer_types()
        customer_type = input("Enter customer type (r/w):\t")
        order_total = Decimal(val.get_float("Enter order total:\t\t", 100000))
        order_total = order_total.quantize(Decimal("1.00"), ROUND_HALF_UP)

        # get invoice date
        invoice_date = get_invoice_date()
        current_date, due_date, days_overdue = calculate_due_date(invoice_date)

        # determine discount for retail customer
        if customer_type.lower() == "r":
            customer_type = "Retail"
            if order_total > 0 and order_total < 100:
                discount_percent = Decimal("0")
            elif order_total >= 100 and order_total < 250:
                discount_percent = Decimal(".1")
            elif order_total >= 250 and order_total < 500:
                discount_percent = Decimal(".2")
            elif order_total >= 500:
                discount_percent = Decimal(".25")

        # determine discount for wholesale customer
        elif customer_type.lower() == "w":
            customer_type = "Wholesale"
            if order_total > 0 and order_total < 500:
                discount_percent = Decimal(".4")
            elif order_total >= 500:
                discount_percent = Decimal(".5")

        # customer is neither wholesale nor retail so discount_percent at zero
        else:
            customer_type = "Unknown"

        # calculate discount and new invoice total
        discount = order_total * discount_percent
        discount = discount.quantize(Decimal("1.00"), ROUND_HALF_UP)

        subtotal = order_total - discount
        tax_percent = Decimal(".05")
        sales_tax = subtotal * tax_percent
        sales_tax = sales_tax.quantize(Decimal("1.00"), ROUND_HALF_UP)
        invoice_total = subtotal + sales_tax

        # display results
        # determine the region for the money
        result = lc.setlocale(lc.LC_ALL, "")
        if result == "C":
            lc.setlocale(lc.LC_ALL, "en_US")
        line = "{:20} {:>10}"
        print()
        print("Customer Type:          {:10}".format(customer_type))
        print(
            line.format("Order total:", lc.currency(order_total,
                                                    grouping=True)))
        print(line.format("Discount:", lc.currency(discount, grouping=True)))
        print(line.format("Subtotal:", lc.currency(subtotal, grouping=True)))
        print(line.format("Sales tax:", lc.currency(sales_tax, grouping=True)))
        print(
            line.format("Invoice total:",
                        lc.currency(invoice_total, grouping=True)))
        print()

        show_due_date(invoice_date, current_date, due_date, days_overdue)

        print()
        choice = input("Try again? (y/n): ")
        if choice.lower() != "y":
            should_Exit = True
        # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")