๐ŸŽฏ MILESTONE 1 - Interactive command line dialog

If youโ€™ve managed to complete exercises 0 to 8, you have built an interactive command line dialog while learning about variables, operations and control flows.

๐Ÿ”‘ Core Concepts

Variables and Data Types

  • Variables: Named containers for storing information (name = "Alice")
  • Strings (str): Text data for names, messages, and user input
  • Integers (int): Whole numbers for counting, scoring, and calculations
  • Floats (float): Decimal numbers for precise measurements
  • Booleans (bool): True/False values for decision making

User input and output

  • Input: Using input() to collect information from users
  • Output: Using print() to display information and results
  • F-strings: Embedding variables in text for clear, readable output
  • Type Conversion: Converting between strings, integers, and floats

Operations

  • Arithmetic Operators: +, -, *, /, %, ** for calculations
  • Comparison Operators: ==, !=, >, <, >=, <= for making decisions
  • String Operations: Concatenation and formatting for user-friendly messages

Control flow

  • If Statements: Making decisions based on conditions
  • If-Elif-Else: Handling multiple possible outcomes
  • While Loops: Repeating actions until a condition is met
  • For Loops: Repeating actions a specific number of times

๐Ÿ›๏ธ Programming Patterns

1. Input โ†’ Process โ†’ Output Pattern

user_input = input("Enter your age: ")  # Input
age = int(user_input)                   # Process
print(f"Next year you'll be {age + 1}") # Output

2. Menu Loop Pattern

while True:
    # Display menu
    print("1. Option 1")
    print("2. Option 2")
    print("3. Exit")
    
    choice = input("Enter choice: ")
    
    if choice == "3":
        break
    elif choice == "1":
        # Do something
    elif choice == "2":
        # Do something else

Used in: Your menu system E.g.

while True:
    print("\n=== Flashcard Practice Menu ===")
    print("1. Set number of cards")
    print("2. Display current score")
    print("3. Start flashcards")
    print("4. Exit")
    
    choice = input("\nEnter your choice (1-4): ")
    
    if choice == "4":
        print("Goodbye!")
        break

3. Input Validation Loop Pattern

while True:
    user_input = input("Enter value: ")
    if valid(user_input):
        break
    else:
        print("Invalid input, try again")

Used in: Ensuring the value entered for preferred number of cards is a number

E.g.

while True:
    num_cards_per_session = input("How many cards would you like to practice?: ")
    if num_cards_per_session.isdigit():
        num_cards_per_session = int(num_cards_per_session)
        break
    else:
        print("You should enter a whole number. Try again")

4. Sentinel loop pattern

# Loop until a specific value (sentinel) is entered
while user_input != "quit":
    user_input = input("Enter command (or 'quit'): ")
    # Process command

Used in: Keep asking until user says โ€œstopโ€ or โ€œquitโ€ E.g.

while True:
    command = input("Enter command (or 'exit' to quit): ")
    if command == "exit":
        break
    process_command(command)

๐Ÿ“– Important Terms

Variable assignment: Using = to store values in named containers (variables) for later use.

Data type conversion: Changing values between different types (e.g., int("25") converts string to integer).

Conditional logic: Using comparison operators (e.g., >, <, ==) and if statements to make decisions in your program.

Loop control: Using while loops for user-controlled repetition and for loops for counted repetition.

User experience: Creating interactive programs that respond appropriately to user input.