プログラミング入門I 確認テスト 2025.11.10

Back


大文字の X と Y の文字コードは 10 進数で 88 と 89 です.XY のどちらかをランダムに 1 個発生させ,1 つ目の X に続けてそれをヒトの性染色体の型とします.発生させた型が染色体上男性か女性(XX: 女性,XY: 男性)かを答えるプログラムを作成しましょう.

The character codes for the uppercase letters X and Y are 88 and 89 in decimal. Randomly generate one of XY, and add it after the first X as the type of human sex chromosome. Create a program that answers whether the generated type is male or female on the chromosome (XX: female, XY: male).

Student number: s246099

Chromosome: XX
Gender: Female

------------------------
Student number: s246099

Chromosome: XY
Gender: Male

------------------------
女性の場合
For women
男性の場合
For men

解答用紙にはあらかじめ基本的な部分が記入されています.??の部分を適切に書き直してください.(?の個数は文字数とは関係ありません.) 考え方としては型の1つ目の X は固定です.次が X か Y かだけを乱数で発生させます.

The basic parts have already been filled in on the answer sheet. Please rewrite the ? ? parts appropriately. (The number of ? has no relation to the number of characters.) The idea is that the first X in the pattern is fixed. Only the next X or Y is generated randomly.
なお,結果の出力では必ず最初の行に自分の学生番号を,最後にハイフンによるラインをつけること.無い場合には減点するので注意.これらは解答用紙にあらかじめ入っているものを自分のものに修正するだけでよいので,必ず行ってください.

解答用紙を使用する際には,学生番号と名前の記入も忘れないでください.さらに,解答用紙自体がPythonのプログラムとなっていますので,実行してエラーの無いことを確認してから提出してください.

指定の解答用紙を使用していない,実行時にエラーが出る,学生番号と名前が無い,というような答案は提出されても採点しません.注意してください.


解答例

# #############################
#
# プログラミング入門I 確認テスト 2025.11.10
# 学生番号:  s246099    
# 氏名:     松江 花子   
#
# #############################

import random

print('Student number: s246099')  
print()

chromo = random.randint(88, 89)
print(f'Chromosome: X{chromo:c}')

if chromo == 88:
    print('Gender: Female')
else:
    print('Gender: Male')

print('\n------------------------\n')


Back