예제 #1
0
import congress

# Congressional representatives have properties like:
# - name
# - party
# - state
# - loyalty_factor (% of votes with their party)
#
# See the congress.py file for more details.

representatives = congress.read_from_file()

### Can you write code to display the correct answers?


# 1. What type of object is held inside the 'representatives' variable?
print(type(representatives))

# 2. How many representatives are there?
print(len(representatives))

# 3. Display the name of the last representative.
print(representatives[-1].name)

# print(representatives)

# 4. Which rep is most loyal to their party?
loyalty = 0
most_loyal = representatives[0].name
# for person in range(len(representatives)):
#   x = representatives[person]
예제 #2
0
import congress

# Congressional representatives have properties like:
# - name
# - party
# - state
# - loyalty_factor (% of votes with their party)
#
# See the congress.py file for more details.

representatives = congress.read_from_file()

### Can you write code to display the correct answers?


# 1. What type of object is held inside the 'representatives' variable?

print(type(representatives))


# 2. How many representatives are there?
print(len(representatives))


# 3. Display the name of the last representative.
print(representatives[-1].name)


# 4. Which rep is most loyal to their party?
loyalty = 0
most_loyal = representatives[0].name
예제 #3
0
파일: 8_asserts.py 프로젝트: sxl257/week5
from congress import ElectedOfficial
from congress import read_from_file

# Congressional representatives have:
# - name
# - party
# - state
# - laziness_factor (% of votes missed)

representatives = read_from_file()

# 1. Make sure that read_from_file() returns a list object.
assert type(representatives) is list

# 2. Ensure that there are 442 representives.
assert 442 == len(representatives)

# 3. Ensure that each item in the list is of type ElectedOfficial
for rep in representatives:
  assert type(rep) is ElectedOfficial



print("Congratulations, all assertions passed!")