Posts

Showing posts from January, 2022

Secret Auction

Image
  Adding to a list in Python Adding to a dictionary in Python #Find mere here: https://my-python-journey.blogspot.com/ from replit import clear #HINT: You can call clear() to clear the output in the console. from art import logo print(logo) print("Blind Auction Program V1") bids = {} bidding_finished = False def find_highest_bidder(bidding_record): highest_bid = 0 winner = "" # bidding_record = {"Angela": 123, "James": 321} for bidder in bidding_record: bid_amount = bidding_record[bidder] if bid_amount > highest_bid: highest_bid = bid_amount winner = bidder print(f"The winner is {winner} with a bid of ${highest_bid}") while not bidding_finished: name = input("What is your name?: ") price = int(input("What is your bid?: $")) bids[name] = price should_continue = input("Are there any other bidders? Type 'yes or 'no'.\n") if should_continue == "no...

Travel Log (nested dictionaries in a list)

Image
travel_log = [ { "country": "France", "visits": 12, "cities": ["Paris", "Lille", "Dijon"] }, { "country": "Germany", "visits": 5, "cities": ["Berlin", "Hamburg", "Stuttgart"] }, ] #TODO: Write the function that will allow new countries to be added to the travel_log. def add_new_country(country_visited, time_visited, cities_visited): new_country = {} new_country["country"] = country_visited new_country["visits"] = time_visited new_country["cities"] = cities_visited travel_log.append(new_country) add_new_country("Russia", 2, ["Moscow", "Saint Petersburg"]) print(travel_log)  

Nesting in directories and lists

  ##Python Dictionaries How to add to a list in Python How to add to a dictionary in Python programming_dictionary = { "Bug": "An error in a program that prevents the program from running as expected.", "Function": "A piece of code that you can easily call over and over again.", } #Retrieving items from dictionary. # print(programming_dictionary["Function"]) #Adding new items to dictionary. programming_dictionary["Loop"] = "The action of doing something over and over again." #Create an empty dictionary. empty_dictionary = {} #Wipe an existing dictionary # programming_dictionary = {} # print(programming_dictionary) #Edit an item in a dictionary programming_dictionary["Bug"] = "A moth in your computer." # print(programming_dictionary) #Loop through a dictionary # for key in programming_dictionary: # print(key) # print(programming_dictionary[key]) ####################################### #Nest...

Converting student scores to grades (Dictionaries)

Image
You have access to a database of `student_scores` in the format of a dictionary. The **keys** in `student_scores` are the **names** of the students and the **values** are their exam **scores**.  Write a program that **converts their scores to grades**. By the end of your program, you should have a new dictionary called `student_grades` that should contain student **names** for **keys** and their **grades** for **values**. T**he final version** of the `student_grades` dictionary will be checked. student_scores = { "Harry": 81, "Ron": 78, "Hermione": 99, "Draco": 74, "Neville": 62, } #TODO-1: Create an empty dictionary called student_grades. student_grades = {} #TODO-2: Write your code below to add the grades to student_grades.👇 for student in student_scores: score = student_scores[student] if score > 90: student_grades[student] = "Outstanding" elif 80 < score < 91: student_grades[student] = ...