Giter Club home page Giter Club logo

himel-sarder / silent-auction--a-python-dictionaries-project Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 15 KB

The Silent Auction project is a Python script that allows users to participate in an auction by submitting their bids anonymously. After all bids are submitted, the program determines the highest bidder and announces the winner without revealing the identities of the other participants.

Home Page: https://replit.com/@AntuSarder/Silent-Auction-A-Python-Dictionaries-Project?v=1

License: MIT License

Python 100.00%
dictionaries python3 pythonprojects textbasedgame

silent-auction--a-python-dictionaries-project's Introduction

Silent Auction

R

Description

The Silent Auction project is a Python script that allows users to participate in an auction by submitting their bids anonymously. After all bids are submitted, the program determines the highest bidder and announces the winner without revealing the identities of the other participants.

History

https://en.wikipedia.org/wiki/First-price_sealed-bid_auction

Use it in Replit

https://replit.com/@AntuSarder/Silent-Auction-A-Python-Dictionaries-Project?v=1

ScreenShots

newImage download Capture2 H

Take a look

Silent.Auction.mp4

Features

  • Anonymous Bidding: Users can submit their bids without revealing their identities.
  • Winner Determination: The program automatically determines the highest bidder and announces the winner while keeping other participants' identities confidential.
  • User-Friendly Interface: Clear prompts and instructions make it easy for users to participate in the auction anonymously.

Installation

  1. Clone the repository to your local machine:

    git clone https://github.com/Himel-Sarder/Silent-Auction--A-Python-Dictionaries-Project.git
  2. Navigate to the project directory:

    cd Silent-Auction--A-Python-Dictionaries-Project
  3. Run the script:

    python Silent Auction.py

Required Skills

  • Python Dictionaries
  • Loop
  • Function
  • If/Else

Usage

  1. Enter your bid amount when prompted.
  2. Continue bidding or type 'no' when asked if there are any other bidders.
  3. The program will announce the winner and their bid amount without revealing other participants' identities.

How to Play Silent Auction

  1. Start the Program: Run the Silent Auction program by executing the Silent Auction.py script.

  2. Join the Auction: Enter your name and the amount you want to bid when prompted. Your bid will remain anonymous, so feel free to bid any amount you're comfortable with.

  3. Continue Bidding: After submitting your bid, you have the option to continue bidding or to stop. If you choose to continue, the program will prompt you to enter another bid.

  4. End Bidding: When you're finished bidding, type 'no' when asked if there are any other bidders. This will signal that you're done bidding and ready to see who the winner is.

  5. Winner Announcement: Once all bids have been submitted, the program will determine the highest bidder and announce the winner. The winner's identity will be revealed, along with the winning bid amount. Other participants' identities will remain confidential.

  6. Enjoy the Victory: If you're the highest bidder, congratulations! You've won the auction. If not, better luck next time!

  7. Play Again: If you enjoyed the auction, feel free to play again by restarting the program and joining a new auction.

Tips for Success:

  • Bid Strategically: Consider the value of the item being auctioned and bid accordingly. Remember, the highest bidder wins, so bid wisely.
  • Stay Informed: Keep track of other participants' bids if possible, but remember that their identities are confidential. Use your bidding strategy to your advantage.
  • Have Fun: Silent auctions are meant to be enjoyable experiences. Relax, bid confidently, and have fun participating!

Contributing

Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request.

Credit

Coded by--

  • Himel Sarder
  • Dept. of Computer Science and Engineering
  • BSFMSTU, Jamalpur, Bangladesh

License

This project is licensed under the MIT License.

Python Dictionaries

What are Python Dictionaries?

Python dictionaries are unordered collections of data in key:value pairs. They are similar to real-world dictionaries, where you look up a word (the key) to find its definition (the value). In Python, dictionaries are extremely versatile and can hold various types of data, including numbers, strings, lists, or even other dictionaries.

Creating a Dictionary

You can create a dictionary in Python using curly braces {} and separating key:value pairs with commas. Here's an example:

# Creating a dictionary
my_dict = {"name": "John", "age": 30, "city": "New York"}

Accessing Values

You can access the values in a dictionary by referring to its key within square brackets [] or by using the get() method. If the key does not exist, accessing it directly will raise a KeyError, while get() will return None or a default value if specified.

# Accessing values
print(my_dict["name"])  # Output: John
print(my_dict.get("age"))  # Output: 30
print(my_dict.get("gender", "Male"))  # Output: Male (default value)

Adding and Modifying Items

You can add new key:value pairs to a dictionary or modify existing ones.

# Adding a new item
my_dict["job"] = "Engineer"

# Modifying an existing item
my_dict["age"] = 31

Removing Items

You can remove items from a dictionary using the del keyword or the pop() method.

# Removing an item using del
del my_dict["city"]

# Removing an item using pop()
job = my_dict.pop("job")

Dictionary Methods

Python dictionaries come with various built-in methods to perform operations on them.

1. keys()

Returns a view of all the keys in the dictionary.

Example:

my_dict = {"name": "John", "age": 30, "city": "New York"}
keys_view = my_dict.keys()
print(keys_view)  # Output: dict_keys(['name', 'age', 'city'])

2. values()

Returns a view of all the values in the dictionary.

Example:

my_dict = {"name": "John", "age": 30, "city": "New York"}
values_view = my_dict.values()
print(values_view)  # Output: dict_values(['John', 30, 'New York'])

3. items()

Returns a view of all the key-value pairs in the dictionary as tuples.

Example:

my_dict = {"name": "John", "age": 30, "city": "New York"}
items_view = my_dict.items()
print(items_view)  # Output: dict_items([('name', 'John'), ('age', 30), ('city', 'New York')])

4. clear()

Removes all items from the dictionary.

Example:

my_dict = {"name": "John", "age": 30, "city": "New York"}
my_dict.clear()
print(my_dict)  # Output: {}

5. update()

Updates the dictionary with the key-value pairs from another dictionary or iterable.

Example:

my_dict = {"name": "John", "age": 30}
new_data = {"city": "New York", "job": "Engineer"}
my_dict.update(new_data)
print(my_dict)  # Output: {'name': 'John', 'age': 30, 'city': 'New York', 'job': 'Engineer'}

6. copy()

Returns a shallow copy of the dictionary.

Example:

my_dict = {"name": "John", "age": 30}
copy_dict = my_dict.copy()
print(copy_dict)  # Output: {'name': 'John', 'age': 30}

7. len()

Returns the number of items in the dictionary.

Example:

my_dict = {"name": "John", "age": 30, "city": "New York"}
print(len(my_dict))  # Output: 3

These methods provide useful functionalities for working with dictionaries in Python, making it easier to manipulate and retrieve data stored in dictionaries.

Looping Through a Dictionary

You can iterate over a dictionary using loops. By default, looping over a dictionary traverses its keys.

# Looping through keys
for key in my_dict:
    print(key, my_dict[key])

# Looping through values
for value in my_dict.values():
    print(value)

# Looping through key-value pairs
for key, value in my_dict.items():
    print(key, value)

Dictionary Comprehensions

Like lists, dictionaries also support comprehensions for creating dictionaries in a concise manner.

# Dictionary comprehension
squares = {x: x*x for x in range(1, 6)}
# Output: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Nested Dictionaries

Nested dictionaries are dictionaries within dictionaries, creating a hierarchical structure to represent more complex data. Here's an example to illustrate nested dictionaries:

# Nested dictionaries example
nested_dict = {
    "person1": {
        "name": "John",
        "age": 30,
        "address": {
            "city": "New York",
            "zip": "10001"
        }
    },
    "person2": {
        "name": "Alice",
        "age": 25,
        "address": {
            "city": "Los Angeles",
            "zip": "90001"
        }
    }
}

In this example, nested_dict contains two key-value pairs, each representing information about a person. Each person's information is stored as another dictionary with keys for name, age, and address. The address key further contains a dictionary with keys for city and zip.

You can access nested dictionary values using multiple square brackets to traverse through the layers:

# Accessing nested dictionary values
print(nested_dict["person1"]["name"])  # Output: John
print(nested_dict["person2"]["address"]["city"])  # Output: Los Angeles

Similarly, you can modify or add elements to nested dictionaries:

# Modifying nested dictionary
nested_dict["person1"]["age"] = 35
nested_dict["person2"]["address"]["city"] = "San Francisco"

# Adding to nested dictionary
nested_dict["person1"]["address"]["street"] = "123 Main St"

Nested dictionaries are useful for representing structured data, such as hierarchical relationships or complex objects, and are commonly used in various programming scenarios.

Python dictionaries are fundamental data structures that offer fast and efficient lookup operations. They are widely used in various Python programs for storing and manipulating data in a flexible manner.

Thank You

silent-auction--a-python-dictionaries-project's People

Contributors

himel-sarder avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.