Giter Club home page Giter Club logo

higherlower's Introduction

HigherLower

Higher/Lower Game, 100 Days of Code Day 14. Simulates a database of instagram accounts and uses them for a game where the user attempts to guess which of the two accounts has the most followers.

game_data.py contains a variable called data which stores the data as a list of dictionaries, each dictionary having 4 keys: 'name': the name of the person or organization the instagram is for 'follower_count': How many followers the account has 'description': What the person/organization is known for 'country': What country the person/organization is from.

art.py contains ASCII art for the title and versus logos

higherlower.py holds all the game logic.

The program begins by using a function called get_entry() that takes in the data list from data.py as an argument and returns a random entry. Two variables, "A" and "B" each store one random entry.

If A and B happen to draw the same entry, get_entry() is rerun for B until they are different.

The logo is then printed, and two more global variables are declared. Score is set to an initial value and zero, and is_playing is set to True. The gameplay loop will continue until is_playing is set to False.

Two functions were created to print formatted strings based on the values of A and B.

  1. print_a() take an entry as an argument and returns a formatted string: "Compare A: {a_name}, a {a_description}, from {a_country}"
  2. print_b() takes an entry as an argument and returns a formatted string: "Against B: {b_name}, a {b_description}, from {b_country}"

A potential improvement would be combining these two into one function.

The functions work using the dictionary.get() method to define variables for the name, description, and country. It would have been possible to use entry['name'], entry['description'] and entry['country'] instead.

After the formatted strings and versus logo have been printed, a variable called user_choice is declared and stores the users guess as to which account has more followers. the user's input is turned to lowercase with lower() to avoid case sensitive errors.

Then, a variable called "higher" is declared and set to the output of compare(). compare() is a function that accepts two entries (A and B) as arguments and returns the entry with the most followers using a simple if/else block.

a function called match_choice() is then called. The purpose of this function is to determine whether the user's choice was correct. match_choice() takes three arguments: user_choice, and both entries (A and B). if user_choice is equal to "a", entry1 (A) is returned. If user_choice is equal to "b", entry2 (B) is returned. For all other cases, the function returns a string: "invalid"

if the output of match_choice() does not equal higher, then is_playing is set to False, the screen is cleared, and the user is told they guessed wrong and their final score. Since match_choice() returns 'invalid' for all inputs other than 'a' or 'b' invalid inputs will always be treated as incorrect answers and therefore end the game.

if the output of match_choice() does match higher, the score is increased by one, A is set to the old value of B, and a new entry is chosen for B. The user is then told they guessed right and their score. The loop starts over, printing the new formatted strings based on the new values of A and B as well as the versus logo.

higherlower's People

Contributors

taky0ndon 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.