Skip to content

Introduction to Python

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

i learnt how to dd differennt types of list and also add a list inside a list (llist of list) and also slicer (how to chose the element to use in a set)

areas = [1.0, 5.0, 10.0]

print (areas)

hall = 1.0
liv = 2.0
bed = 5.0
study = 20.0

area = ["halllway", hall, "livingroom", liv,  "bedroom", bed, "library", study]
print (area)

#list of llist
house  = [["hallway", hall],
         ["livingroom", liv],
         ["bedroom", bed],
         ["library", study]]
print (house)

print (house[0]) #  for he firstelement of the set
print (area[0])

print (house[-1]) #negative selection for the last element
print (area[-1])

print (house[0:2]) # for slection of the first elemen excluding the fifth
print (area[0:4])

print (house[2:]) # for selecting thhe fifth element till the end 
print (area[2:])
print (area[4:])

# indexing start with 0 which is the first element

# llearnt alll other functions like list methods count, uppercasing, indexig

place = "poolhouse"
print (str.upper(place))
# for count
print (area.count("o"))
#indexing
print (area.index(bed))
#we canalso add values to existing llist using append
print (max(areas))
# oters are sorted(list, argument rg reverse=True) returns the list in a descendingorder

I learnt how to input values _from int to _str, float,and _bool _

i also learnt to convert from a type to another

initial = 100
addition = 50

savings = initial + addition

print ( "i had $" + str(initial) + "now i have $" + str(savings))

Add your notes here

# Add your code snippets here

Explore Datasets

Use the arrays imported in the first cell to explore the data and practice your skills!

  • Print out the weight of the first ten baseball players.
  • What is the median weight of all baseball players in the data?
  • Print out the names of all players with a height greater than 80 (heights are in inches).
  • Who is taller on average? Baseball players or soccer players? Keep in mind that baseball heights are stored in inches!
  • The values in soccer_shooting are decimals. Convert them to whole numbers (e.g., 0.98 becomes 98).
  • Do taller players get higher ratings? Calculate the correlation between soccer_ratings and soccer_heights to find out!
  • What is the average rating for attacking players ('A')?