Skip to content

Instantly share code, notes, and snippets.

@seven0525
Last active May 29, 2018 07:52
Show Gist options
  • Save seven0525/87fb1c8ecbee29778ed5cdbbfd234708 to your computer and use it in GitHub Desktop.
Save seven0525/87fb1c8ecbee29778ed5cdbbfd234708 to your computer and use it in GitHub Desktop.
「自作Python100本ノック」2日目(6本〜10本目) ref: https://qiita.com/ahpjop/items/909fd55e48211dab2c5c
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)
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)
def count_z(n):
print((n // 3 * 2) + n // 5 * 2)#「//」は割り算の整数部分の結果を出します
count_z(100)
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()))
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