Last active
April 29, 2025 00:25
-
-
Save sdkfz181tiger/2ba69f22a82e4368d4a3a7fac35556e5 to your computer and use it in GitHub Desktop.
Python3_定番ハンズオン7選_2025
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
# coding: utf-8 | |
""" | |
Hello World | |
""" | |
#========== | |
# Main | |
import math, random | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
i_name = input("名前を入力してください") | |
print("こんにちは, " + i_name + "さん!!") | |
i_age = int(input("年齢を入力してください")) | |
if i_age < 13: | |
print("少年です!!") | |
elif i_age < 18: | |
print("青年です!!") | |
elif i_age < 30: | |
print("成人です!!") | |
elif i_age < 65: | |
print("中年です!!") | |
else: | |
print("高齢です!!") | |
i_sum = int(input("数字を入力してください")) | |
print("1 ~ " + str(i_sum) + "までの合計値を計算します") | |
i_total = 0 | |
for i in range(i_sum): | |
i_total = i_total + i + 1 | |
print("合計値は" + str(i_total) + "です") | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
サイコロ | |
""" | |
#========== | |
# Main | |
import math, random | |
def show_dice(num): | |
print("show_dice:", num) | |
if num == 1: | |
print("+-------+") | |
print("| |") | |
print("| ● |") | |
print("| |") | |
print("+-------+") | |
return | |
if num == 2: | |
print("+-------+") | |
print("| ● |") | |
print("| |") | |
print("| ● |") | |
print("+-------+") | |
return | |
if num == 3: | |
print("+-------+") | |
print("| ● |") | |
print("| ● |") | |
print("| ● |") | |
print("+-------+") | |
return | |
if num == 4: | |
print("+-------+") | |
print("| ● ● |") | |
print("| |") | |
print("| ● ● |") | |
print("+-------+") | |
return | |
if num == 5: | |
print("+-------+") | |
print("| ● ● |") | |
print("| ● |") | |
print("| ● ● |") | |
print("+-------+") | |
return | |
if num == 6: | |
print("+-------+") | |
print("| ● ● |") | |
print("| ● ● |") | |
print("| ● ● |") | |
print("+-------+") | |
return | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
rdm = random.randint(1, 6) | |
show_dice(rdm) | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
おみくじ | |
""" | |
#========== | |
# Main | |
import math, random | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
rdm = random.randint(0, 6) | |
if rdm == 0: | |
print("大吉です!!") | |
elif rdm == 1: | |
print("中吉です!!") | |
elif rdm == 2: | |
print("小吉です!!") | |
elif rdm == 3: | |
print("吉です!!") | |
elif rdm == 4: | |
print("末吉です!!") | |
elif rdm == 5: | |
print("凶です!!") | |
else: | |
print("大凶です!!") | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
数当てゲーム | |
""" | |
#========== | |
# Main | |
import math, random | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
n_min = 0 | |
n_max = 10 | |
n_answer = random.randint(n_min, n_max+1) | |
while(True): | |
msg = "ヒント: " + str(n_min) + "~" + str(n_max) + " までの範囲です" | |
n_input = int(input(msg)) | |
print("n_input:", n_input) | |
if n_input < n_answer: | |
print("残念、" + str(n_input) + "より大きい数字です") | |
n_min = n_input + 1 | |
continue | |
if n_answer < n_input: | |
print("残念、" + str(n_input) + "より小さい数字です") | |
n_max = n_input - 1 | |
continue | |
print("正解です:", n_answer) | |
break | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
ピラミッド | |
""" | |
#========== | |
# Main | |
import math, random | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
i_height = input("高さを入力してください") | |
n_height = int(i_height) | |
print("高さ:", n_height) | |
print("Type-A") | |
for r in range(n_height): | |
line = "" | |
for c in range(r+1): | |
line += "*" | |
print(line) | |
print("Type-B") | |
for r in range(n_height): | |
line = "" | |
for c in range(n_height-(r+1)): | |
line += "_" | |
for c in range(r+1): | |
line += "*" | |
print(line) | |
print("Type-C") | |
for r in range(n_height): | |
line = "" | |
for c in range(n_height-(r+1)): | |
line += "_" | |
for c in range(r*2+1): | |
line += "*" | |
print(line) | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
ジャンケン | |
""" | |
#========== | |
# Main | |
import math, random | |
HANDS = ["グー", "チョキ", "パー"] | |
msg = "1: グー, 2: チョキ, 3, パー, q: 終了" | |
n_win = 0 | |
n_lose = 0 | |
n_even = 0 | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
global n_win, n_lose, n_even | |
while(True): | |
i_you = input(msg) | |
if i_you == "q": break | |
# You | |
n_you = int(i_you) | |
if n_you < 1 or len(HANDS) < n_you: continue | |
# Com | |
n_com = random.randint(1, len(HANDS)) | |
print("YOU:", HANDS[n_you-1], "vs COM:", HANDS[n_com-1]) | |
# Result | |
result = (n_com - n_you + 3) % 3 | |
if result == 1: | |
print("勝ちました") | |
n_win += 1 | |
elif result == 2: | |
print("負けました") | |
n_lose += 1 | |
else: | |
print("あいこです") | |
n_even += 1 | |
print("成績", "Win(", n_win, "), Lose(", n_lose, "), Even(", n_even, ")") | |
if __name__ == "__main__": | |
main() |
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
# coding: utf-8 | |
""" | |
タイピングゲーム | |
""" | |
#========== | |
# Main | |
import math, random | |
WORDS = ["abc", "def", "ghi", "jkl", "mno"] | |
total = len(WORDS) | |
index = 0 | |
score = 0 | |
def main(): | |
print("main!!") | |
#random.seed(0)# Seed | |
global total, index, score | |
while(True): | |
answer = WORDS[index] | |
msg = "[問" + str(index+1) + "]: " + answer + ", q: 終了" | |
i_you = input(msg) | |
if i_you == "q": break | |
if i_you == answer: | |
print("GOOD!!") | |
score += 1 | |
else: | |
print("BAD...") | |
if index < total-1: | |
index += 1 | |
continue | |
break | |
print("結果:" + str(score) + "/" + str(total) + "点") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment