Skip to content

制御構文の解答 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions euclid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
b = input("b の値を入力: ")

# TODO
while b != 0:
a,b = b, int(a) % int(b)
print('最大公約数:{}'.format(a))


6 changes: 5 additions & 1 deletion machine_epsilon.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# TODO
# TODO
epsilon = 1
while 1 + epsilon > 1:
epsilon = epsilon/2
print(epsilon)
17 changes: 16 additions & 1 deletion prime_number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
a = input("aの値を入力: ")
b = input("bの値を入力: ")

# TODO
# TODO
for x in [a,b]:
if int(x) < 2:
print('{}は素数ではない'.format(x))
continue

is_prime = True
for i in range(2,int(x)):
if int(x) % i ==0:
is_prime = False
break

if is_prime:
print('{}は素数'.format(x))
else:
print('{}は素数ではない'.format(x))
20 changes: 20 additions & 0 deletions trapezoidal_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@
# print(sin(0))
# >>> 0
# -----------
from math import pi
h = ( pi/2 - 0 ) / 100
S=0
for i in range(1,101):
S += h/2 * (sin(0+(i-1)*h)+ sin(0+i*h))
print(S)