exercise001_條件判斷

林不肯先森發表於2018-07-09
#coding=utf-8
# 1:一個足球隊在尋找年齡在10歲到12歲的小女孩(包括10歲和12歲)加入。
# 編寫一個程式,詢問使用者的性別(m表示男性,f表示女性)和年齡,
# 然後顯示一條訊息指出這個人是否可以加入球隊,
# 詢問10次後,輸出滿足條件的總人數。
# 此題利用while迴圈和if條件一起來做!

count = 0
male="m"
female="f"
for num in range(0,10):
    sex = str(raw_input("Please input your sex ,m for male f for female: "))
    if sex == female:
        print("Nice! you are female")
        age = int(raw_input("Next,Please input you age : "))
        if 10 <= age <=12:
            count = count + 1
            print("congratulations you are admitted")
        else:
            print("sorry, only children in aged 10-12 can be admitted ")
    else:
        print("sorry, only female can be admitted ")
print("there are ", count, "children be admitted")
Please input your sex ,m for male f for female: m
sorry, only female can be admitted 
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 11
congratulations you are admitted
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 33
sorry, only children in aged 10-12 can be admitted 
Please input your sex ,m for male f for female: e
sorry, only female can be admitted 
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 11
congratulations you are admitted
Please input your sex ,m for male f for female: ff
sorry, only female can be admitted 
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 11
congratulations you are admitted
Please input your sex ,m for male f for female: m
sorry, only female can be admitted 
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 11
congratulations you are admitted
Please input your sex ,m for male f for female: f
Nice! you are female
Next,Please input you age : 1
sorry, only children in aged 10-12 can be admitted 
('there are ', 4, 'children be admitted')

相關文章