ποΈ Week 01 β Day 02: Data Types & Common File Formats
How is data stored in computer memory?
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.
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:<- sample(1:100, 10, replace = TRUE) random_numbers
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.randint(1, 100) for _ in range(10)] random_numbers
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 number3
because1
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 number2
, as Python is zero-indexed.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 returnc(3, 5)
because the numbers4
and2
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.