Created
May 22, 2021 21:45
-
-
Save x1001000/2403c1a96932e611821746c95f99d51e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 男生人數和女生人數初始值皆設為0 | |
N_males = N_females = 0 | |
with open('read.dat') as f: | |
for line in f.readlines(): | |
print(line) | |
N = line.split()[-2] | |
# 排除檔案第一行切出來的N為'性別'的情況 | |
if N == '0': | |
N_females += 1 | |
if N == '1': | |
N_males += 1 | |
print(f'Number of males: {N_males}') | |
print(f'Number of females: {N_females}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment