while True:

プログラミング演習(備瀬 竜馬)

第8回

小問番号はコメント(#)を参照
# 8_A_1
for x in range(5):
    k = int(input("Input number:"))
    print("Number:{}".format(k))


# 8_A_2
total = 0
for x in range(5):
    k = int(input("number{}:".format(x + 1)))
    total = total + k
print("Average:{}".format(total/5))


# 8_B_1
num = int(input("Input number:"))
for x in range(num):
    print(x)


# 8_B_2
num = int(input("Input number:"))
for x in range(0, num, 3):
    print(x)


# 8_C_1
num = int(input("Input number:"))
check = True
if num % 2 == 0 and num > 2:
    print("素数じゃないなり")
    exit(0)
for x in range(3, num//2 + 1, 2): # 半分まで奇数で割っていく
    if num % x == 0:
        check = False
        break
if check:
    print("素数なり")
else:
    print("素数じゃないなり")


# 8_C_2
char = input("Input char:")
char2 = ""
for x in char:
    char2 = x + char2
if char == char2:
    print("回文です")
else:
    print("回文ではありません")


# 8_C_3
char = input("Input char:")
k = int(input("Input SHIFT(k):"))
char2 = ""
for x in char:
    value1 = ord(x)
    k = k % 26
    value2 = value1 + k
    if value2 > 122:
        value2 = value2 - 26
    char2 = char2 + chr(value2)
print(char2)
  
ページのトップへ戻る