def square(x):
return x*x
sq = square(6)
print(sq)
36
for x in range(10):
print(x,square(x))
0 0 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81
def convert_hours(hours):
if hours == 0:
return "zero"
if hours == 1:
return "one"
def letter_grade(points):
if points >= 90:
return "A"
elif points >= 80:
return "B"
elif points >= 70:
return "C"
elif points >= 60:
return "D"
else:
return "F"
print(letter_grade(87) + " Congrats for doing well")
answer = letter_grade(87)
print(answer)
B Congrats for doing well B
# Collections: lists/tuples, sets, dictionaries
grocery_list = ["apples","meat","green beans"]
quantity = [10,2,5]
grocery_list[2] # index a list
len(grocery_list)
3
nums = [10,20,30,40,50,60,70,80]
nums[3:7] # slice
nums[:7]
nums[3:]
nums[:]
nums[3:7:2]
nums[::-1]
[80, 70, 60, 50, 40, 30, 20, 10]