Python練習——判断とサイクル

2632 ワード

Pythonベースまとめ(判断とループ)
じょうけんけってい
# coding: utf-8

# score = input('Please input score: ')
score = 85

'''
1.        ,       
'''
if score >= 60:
    print("  ")
else:
    print("   ")
    

'''
2.        ,           

100 ~ 80( 80):   
 80 ~ 70( 70):   
 70 ~ 60( 60):   
 60 ~ 0 ( 00):    
'''
if score >= 80 and score <= 100:
    print('  ')
elif score >= 70 and score < 80:
    print('  ')
elif score >= 60 and score < 70:
    print('  ')
else:
    print('   ')


じゅんかんこうぞう
# coding: utf-8

'''
      
for  in :
    

while :
    


        
  ,   ,   ,   ,     

break  continue
'''

scores = [ 80, 76, 54, 87, 90, 61, 56, 89, 93, 58, 98, 71 ]

#    scores     
s = 0
for x in scores:
    # s = x + s
    s += x
# print(s)

#      
avg = round(s / len(scores), 2)
# print(avg)

#          
f = scores[0]
h = scores[0]
for i in scores:
    if i >= f:
        f = i
    elif i <= h:
        h = i
# print(h)

# print(f)
# print('max =', max(scores))
# print('min =', min(scores))


#      
copy = scores.copy()
copy.sort()
length = len(copy)
if length == 0:
    print('    ')
if length % 2 == 1:
    mid = (length + 1) // 2
    mid_number = copy[mid-1]
elif length % 2 == 0:
    mid = (length) // 2
    mid_number = (copy[mid - 1] + copy[mid]) / 2
# print(mid_number)
# print(copy)



#   
students = [
    {
        'name': 'Mika',
        'age': 18,
    },
    {
        'name': 'Ellis',
        'age': 18,
    },
    {
        'name': 'Harriette',
        'age': 22,
    },
    {
        'name': 'Douglas',
        'age': 23,
    },
    {
        'name': 'Lorine',
        'age': 21,
    },
    {
        'name': 'Wendell',
        'age': 19,
    },
    {
        'name': 'Annamaria',
        'age': 24,
    },
    {
        'name': 'Wendell',
        'age': 19,
    },
]

'''
    :
Rank1: My name is Mika, I am 18 years old.
'''
# for student in students:
#     # print(student, end=' : ')
#     for key in student:
#         print(student[key])

# range(len(students)) == [0, 1, 2, 3, 4, 5, 6, 7]
for i in range(len(students)):
    print(i, students[i]['name'], students[i]['age'])

# for index, value in enumerate(students):
#     print(index, value)