(Nov 3) For all Python assignments submitted after Nov 6, please use the skeleton codes provided in each assignment (except PY1). Submission before Nov 6, you can submit assignments without using the skeleton codes.
以下のような命令を受け付けて実行することを繰り返す英和辞書プログラムを考える。命令は標準入力で与えられ、命令の区切りは改行で、1命令中の単語の区切りは空白文字である。各単語に空白文字は現れないと仮定する。
「insert <word> <tango>」: <word>の翻訳が<tango>であるとデータベースに登録する。既に登録されている場合は上書きする。
「delete <word>」: <word>をデータベースから削除する。("(not found)" を上書きするのではなく、データベースから削除する実装をする。2021.12.28 追記)
「search <word>」: <word>をデータベースから検索し、その翻訳を表示する。 単語がデータベースに存在しないときには、「(not found)」と表示する。
「quit」: プログラムを終了する。
例えば、次のようなものが正しい入力である。
insert orange オレンジ
insert apple リンゴ
insert grape 葡萄
insert pear 梨
insert strawberry 苺
insert raspberry 木苺
insert fig 無花果
insert kaki 柿
insert apricot 杏
insert peach 桃
search apricot
insert orange 蜜柑
search orange
delete orange
search orange
search kaki
quit
この入力に対するプログラムの出力は、以下のようになる。(プロンプトや説明など余計な出力はしない。)
杏
蜜柑
(not found)
柿
内部のデータベースとしてpython dictionaryを使い、上述の単語帳プログラムをpythonで作成せよ。入力に日本語特有の文字が含まれているが、特に気にせずにコードを書いても問題はない。また、正しい入力のみが入力されると仮定して良い。
締切: 01/19 23:59
The input will be multiple integer numbers separated by white space, please compute the sample mean and variance of these numbers.
For example, given the following input
10 6 7 8
The answer should be
7.75
2.19
Please use the main function directly.
def main():
count = 0
numbers = list(map(int,input().split(" ")))
mean_val = Mean(numbers)
var_val = Var(numbers)
print(f'{mean_val:.2f}')
print(f'{var_val:.2f}')
if __name__ == "__main__":
main()
締切: 01/19 23:59
Given a target integer number and a list of integers, return indices of the two numbers such that they add up to the target integer number.
For example, given the following input
20
2 8 12 15
The answer should be
1
2
Please use the main function directly.
def main():
count = 0
target_sum = int(input())
numbers = list(map(int,input().split(" ")))
indices = two_sum(numbers, target_sum)
if len(indices) == 0:
print('(not found)')
else:
for i in range(2):
print(f'{indices[i}}')
if __name__ == "__main__":
main()
締切: 01/19 23:59
Please implement a function Sqrt: given an input number x, return the squared root of x rounded down to the nearest integer. You cannot use any Python built-in function, math library, or numpy library. For example, do not use x**0.5 or int(math.sqrt(x)). Please note that it is possible that the input number does not have a real number squared root. In this case, please print "NG".
Please use the main function directly.
def main():
input_num = int(input())
sqrt_root = Sqrt(input_num)
print(f'{sqrt_root}')
if __name__ == "__main__":
main()
締切: 01/19 23:59
Given two integer numbers represented as strings (s1 and s2), return the sum of these numbers after converting them into integers. You cannot use the Python built-in type casting function: int(s1).
For example, given the follwing input
29002 21496
The answer should be
50498
Please use the main function directly.
def main():
str_nums = input().split()
sum_result = add_two_string_numbers(str_nums[0], str_nums[1])
print(f'{sum_result}')
if __name__ == "__main__":
main()
締切: 01/19 23:59