Python Session 18

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

Code in

Python
Session 18
Create a list
This week’s topics:
1.Lists
2.More conditionals (if statements)

3.my_list = [1, 3, "Michele", [5, 6, 7]]


4.for element in my_list:
5. print(element)
CREATING A Grade

Let’s say I want to make a piece of code that converts from a numerical
grade (1-100) to a letter grade (A, B, C, D, F).

grade = int(input("Enter your grade: "))


if grade >= 90:
print("A")
elif grade >= 80:
print("B")
elif grade >= 70:
print("C")
elif grade >= 65:
print("D")
else:
print("F")
Create list with range
create lists of numbers in Python.
To create a list of numbers from 2 to 10

x = range(2, 11)

for elem in x:
print elem
List Compare
1.Randomly generate two lists to test this

2. list_of_students = ["Michele", "Sara", "Cassie"]

3. name = input("Type name to check: ")


4. if name in list_of_students:
5. print("This student is enrolled.")
Odd or Even

Concepts for this week:


•Modular arithmetic (the modulus operator)
•Conditionals (if statements)
•Checking equality

•if age > 17:


• print("can see a rated R movie")
•elif age < 17 and age > 12:
• print("can see a rated PG-13 movie")
•else:
• print("can only see rated PG movies")

•if a == 3:
• print("the variable has the value 3")
•elif a != 3:
• print("the variable does not have the value 3")

•if a == 3:
• print("the variable has the value 3")
•else:
• print("the variable does not have the value 3")
THANK YOU

You might also like