Last active
May 29, 2018 07:52
-
-
Save seven0525/87fb1c8ecbee29778ed5cdbbfd234708 to your computer and use it in GitHub Desktop.
「自作Python100本ノック」2日目(6本〜10本目) ref: https://qiita.com/ahpjop/items/909fd55e48211dab2c5c
This file contains 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 j_hash(n): | |
s = str(n) | |
array = list(map(int, list(s))) | |
a = sum(array) | |
if n % a == 0: | |
print("Hashnumber") | |
else: | |
print("Not hashnumber") | |
j_hash(444) |
This file contains 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
for i in range(1, 101): | |
if i % 15 == 0: | |
print("Fizz Buzz!") | |
elif i % 3 == 0: | |
print("Fizz!") | |
elif i % 5 == 0: | |
print("Buzz!") | |
else: | |
print(i) |
This file contains 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 count_z(n): | |
print((n // 3 * 2) + n // 5 * 2)#「//」は割り算の整数部分の結果を出します | |
count_z(100) |
This file contains 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
class YenToCurrency: | |
def __init__(self,yen): | |
self.yen = yen | |
def doll(self): | |
doll = self.yen / 109 | |
return(doll) | |
def euro(self): | |
euro = self.yen / 129 | |
return(euro) | |
exchange = YenToCurrency(3000) | |
print('3000円は{}ドルです。'.format(exchange.doll())) | |
print('3000円は{}ユーロです。'.format(exchange.euro())) |
This file contains 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
class Character: | |
def __init__(self,name,maxhp,attack_point,defence_point): | |
self.name = name | |
self.maxhp = maxhp | |
self.hp = maxhp | |
self.attack_point = attack_point | |
self.defence_point = defence_point | |
def status(self): | |
return "{}:体力 {}/{}:攻撃力 {} 防御力 {}".format(self.name,self.hp,self.maxhp,self.attack_point,self.defence_point) | |
def attack(self,enemy): | |
cal_attack_point = self.attack_point - enemy.defence_point | |
enemy.hp -= cal_attack_point | |
print("{}の攻撃!{}に{}のダメージ!".format(self.name,enemy.name,cal_attack_point)) | |
yusha = Character("勇者",60,10,2) | |
slime = Character("スライム",15,5,1) | |
# ステータスを表示 | |
print(yusha.status()) | |
print(slime.status()) | |
# 勇者の攻撃 | |
yusha.attack(slime) | |
# スライムの攻撃: | |
slime.attack(yusha) | |
# ステータスを表示 | |
print(yusha.status()) # 勇者のステータス | |
print(slime.status()) # スライムのステータス |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment