πŸ—“οΈ Week 01 – Day 02: Data Types & Common File Formats

How is data stored in computer memory?

Author
Published

09 July 2024

Nothing better to start the day than a good programming puzzle, right? Let’s get to it!

Part 1: πŸ§‘β€πŸ’» Programming Practice

More practically, we will go over the following:

  • Solve any questions you might have from yesterday’s lab
  • Let’s do a few programming puzzles (without any data) to help us reach a consensus: R or Python?
  • Sort out pending installation issues you might have

Programming puzzles

πŸ‘₯ WORK IN GROUPS

Pair up with colleagues and work on the following programming puzzles. You can choose to code in either R or Python. Try to compare your solutions with your partner’s and discuss the differences.

  1. Create a list of random integers and calculate the sum of all the numbers in the list.

    πŸ’‘ Tips

    R:

    To generate random integers in R, you can use the sample function. For example, to generate 10 random numbers between 1 and 100, you can use the following code:

    random_numbers <- sample(1:100, 10, replace = TRUE)

    Python:

    In Python, you can use the random module to generate random numbers. For example, to generate 10 random integers between 1 and 100, you can use the following code:

    import random
    random_numbers = [random.randint(1, 100) for _ in range(10)]
  2. Write code that identifies the position of the smallest number in a list of numbers. Ensure your code works for any list of numbers.

    πŸ‘‰ Suppose the input list is [9, 11, 1, 7, 2]. If coding in R, then your code should return the number 3 because 1 is the smallest number in there and it is at the third position in the list. If coding in Python, your code should return the number 2, as Python is zero-indexed.

  3. Write code that identifies the position of all even numbers in a list of numbers.

    πŸ‘‰ Consider the same input list as above, [9, 11, 4, 7, 2]. If coding in R, your code should return c(3, 5) because the numbers 4 and 2 are even and placed at the third and fifth position of the list. If coding in Python, the returned list should be [2, 4]

πŸ‘¨β€πŸ« Lecture Slides

Either click on the slide area below or click here to view it in fullscreen. Use your keypad to navigate the slides.

πŸŽ₯ Looking for lecture recordings? You can only find the links to those on Moodle.

πŸ“Ÿ Communication

  • Feel free to use our Slack channels to ask questions or share anything you find interesting.