Skip to main content

Exercices for Data Types

Exercise Set 1: Numeric Types

  1. Number Play Create a program using different numeric types:

    • Create an integer variable with a large number
    • Create a float variable with many decimal places
    • Perform basic math with both
    • Convert between int and float
    • Print all results
  2. Calculator Plus Write a program that:

    • Creates two float numbers
    • Performs division and shows the result
    • Converts the result to an integer
    • Shows what information was lost in the conversion

Exercise Set 2: Strings

  1. String Explorer Create a program that:

    • Creates strings using both single and double quotes
    • Creates a string with a quote inside it
    • Creates a multi-line string
    • Prints each string on a separate line
  2. String Operations Write code that:

    • Creates two strings
    • Concatenates them with a space between
    • Counts the characters in the result
    • Creates a comment predicting the count before running the code

Exercise Set 3: Lists and Tuples

  1. List Basics Create a program that:

    • Creates a list with different types of items
    • Prints specific items by index
    • Modifies an item in the list
    • Adds a new item to the list
    • Prints the list after each change
  2. Tuple vs List Write code that:

    • Creates a tuple and a list with the same values
    • Tries to modify both (the tuple will cause an error)
    • Comments explaining the difference between tuple and list

Exercise Set 4: Dictionaries

  1. Simple Contact List Create a program that:
    • Creates a dictionary for a person's contact details
    • Includes name, age, email, and phone
    • Prints specific values using keys
    • Adds a new key-value pair
    • Modifies an existing value

Challenge Exercises

  1. Mini Database Create a program that:
    • Uses a list of dictionaries to store data about friends
    • Each dictionary should have name, age, and hobbies (as a list)
    • Adds at least three friends
    • Prints specific information about each friend
    • Modifies information for one friend
    • Adds a new friend
    • Uses proper formatting for output