Last active
August 14, 2018 11:34
-
-
Save dhirabayashi/baf1195919d9d76834854a3472c9f82e 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
table = {'1': '一', '2': '二', '3': '三', '4': '四'} | |
print('プログラムを開始します。終了の際は999を入力して下さい。') | |
while True: | |
print('番号を入力して下さい。(1~4) > ', end='') | |
num = input().rstrip() | |
if num == '999': | |
print('お疲れ様でした。') | |
break | |
if num in table: | |
print(table[num] + 'が選択されました。') | |
else: | |
print('番号は1から4の間で選択して下さい。') |
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
def add(x, y): | |
return '+', x + y | |
def subtract(x, y): | |
return '-', x - y | |
def multiply(x, y): | |
return '*', x * y | |
def divide(x, y): | |
return '/', x // y, x % y | |
print('プログラムを開始します。終了の際は999を入力して下さい。') | |
while True: | |
print('番号を入力して下さい。(1:加算 2:減算 3:乗算 4:除算 999:終了) > ', end='') | |
op = input().rstrip() | |
if op == '999': | |
print('お疲れ様でした。') | |
break | |
if op == '1': | |
print('1:加算を行います。') | |
calc = add | |
elif op == '2': | |
print('2:減算を行います。') | |
calc = subtract | |
elif op == '3': | |
print('3:乗算を行います。') | |
calc = multiply | |
elif op == '4': | |
print('4:除算を行います。') | |
calc = divide | |
else: | |
print('番号は1から4の間で選択して下さい。') | |
continue | |
print('一番目の数字を入力して下さい。 > ', end='') | |
num1 = input().rstrip() | |
if not num1.isdecimal(): | |
print('数値を入力してください。') | |
continue | |
num1 = int(num1) | |
print('二番目の数字を入力して下さい。 > ', end='') | |
num2 = input().rstrip() | |
if not num2.isdecimal(): | |
print('数値を入力してください。') | |
continue | |
num2 = int(num2) | |
t = calc(num1, num2) | |
print('{}{}{}'.format(num1, t[0], num2)) | |
print('答えは[{:,}]'.format(t[1]), end='') | |
if len(t) == 3: | |
print(' 余り[{:,}]です'.format(t[2])) | |
else: | |
print('です') |
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
import sys | |
year = int(sys.argv[1]) | |
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): | |
print('うるう年') | |
else: | |
print('うるう年でない') |
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
import sys | |
num = int(sys.argv[1]) | |
print(2) | |
for i in range(3, num + 1, 2): | |
if i == 3: | |
print(i) | |
else: | |
is_prime = True | |
for j in range(3, i, 2): | |
if i % j == 0: | |
is_prime = False | |
break | |
if is_prime: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment