Python Exception Handling Rise Lecture Questions

Asked 2 years ago, Updated 2 years ago, 44 views

#-*- coding:utf-8 -*-
school = {'1 class' : [172, 185, 193, 177, 196], '2 class' : [165, 173, 191, 189, 178]}

for class_number, students in school.items():

    for student in students:
        if student>190:
            print(class_number), 'There are students who are over 190 in class.')
            break

If you follow the example,

It comes out like this... I used utf-8 before that, but I don't know what's wrong here.

Is it the same problem when I read the json file?

python-2.x

2022-09-21 19:15

1 Answers

You must use the python3 command to run Python3 on your Mac.

Try python3 code.py.

Additional answers If you want to use it on Python2, you can do it like this.

# -*- coding: utf-8 -*-

school = {u"1 class": [172, 185, 193, 177, 196], u"2 class": [165, 173, 191, 189, 178]}

for class_number, students in school.items():

    for student in students:
        if student>190:
            There are students over 190 in print(u"{}.format(class_number))
            break


2022-09-21 19:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.