Last active
December 9, 2019 03:51
-
-
Save yue4u/0304eef034767d1542e34ec7d1e8f2e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
問7.リストないしはディクショナリーを用いた処理: | |
添付として共有したファイル(univ.txt)には東京都内の大学一覧が記載されている。 | |
その中から「亜細亜大学」のような大学名に同じ文字が複数用いられているものを判定して、 | |
すべて表示するプログラムを実装せよ | |
""" | |
with open("univ.txt", "r") as f: | |
lines = f.readlines() | |
for line in lines: | |
if len(set(line)) != len(line): | |
print(line) | |
""" | |
問9.文字列操作: | |
以下の要件に相当する関数を実装し、Inputから入力する文字列を取得してテストするプログラムを実装せよ | |
・ この関数は、文字列をひとつ引数に取り、処理をした結果の文字列を戻り値として返す | |
・ 引数の文字列を整数の数字に変換して、1からその数字までの和を求め、結果の数字を文字列に変換する | |
・ 引数の文字列を整数の数字に変換できなかったり、変換結果が0以下の場合は、”ERROR”という文字列を返す | |
(WEB系企業週社試験、過去問より改変) | |
""" | |
def main(input_str: str) -> str: | |
try: | |
_number = int(input_str) | |
if _number <= 0: | |
raise ValueError | |
_sum = sum(range(_number + 1)) | |
return str(_sum) | |
except ValueError: | |
return 'Error' | |
print(main(input())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment