Last active
May 29, 2018 07:51
-
-
Save seven0525/380252a7553b5f6cc5d108fdc20a441c to your computer and use it in GitHub Desktop.
「自作Python100本ノック」1日目(はじめに〜5本目) ref: https://qiita.com/ahpjop/items/373f807d68044cda1c9b
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
s = 0 | |
for i in range(1,51): | |
s += i | |
print(s) |
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(2,1001): | |
for n in range(2,i): #2からその数より以前の数で割り切れないものが素数となる | |
if i%n == 0: | |
break | |
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
a = 0 | |
b = 1 | |
for i in range(10): | |
print(b) | |
a, b = b, a+b |
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 gcd(a,b): | |
if b == 0: | |
return a | |
else: | |
return gcd(b,a%b) #この方法で最大公約数が求められます。 | |
a = 16 | |
b = 6 | |
xab = gcd(a,b) | |
print(xab) | |
#最小公倍数 | |
zab = a*b/xab #この方法で最小公倍数が求められます。 | |
print(zab) |
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(0,101): | |
if "3" in str(i) or 0 == i % 3: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment