ホーム » 2020 » 6月 » 02

日別アーカイブ: 2020/06/02

2020年6月
 123456
78910111213
14151617181920
21222324252627
282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,436 アクセス



弦と矢と半径 – 5

PHP から Python の呼び出しで,Python のコマンドライン引数を使用する.

<?php

	echo	("call python\n") ;

	echo	("\n") ;
	system	("python r_cs.py r_cs 6 1") ;
	system	("python r_cs.py s_rc 5 6") ;
	system	("python r_cs.py c_rs 5 1") ;

	echo	("\n") ;
	system	("python r_cs.py r_cs 8 2") ;
	system	("python r_cs.py s_rc 5 8") ;
	system	("python r_cs.py c_rs 5 2") ;

	?>

Python のコードは,

import	sys
import	math

def	r_cs	(c , s)	:	return	(        ( c*c )  / ( 8 *s ) +  s/2 )
def	s_rc	(r , c)	:	return	( r-math.sqrt(r*r - (c/2)*(c/2) )   )
def	c_rs	(r , s)	:	return	(   math.sqrt(r*r - (r-s)*(r-s) )*2 )

cmd =       sys.argv[1]
p1  = float(sys.argv[2])
p2  = float(sys.argv[3])

print	(cmd + " " + str(p1) + " " + str(p2))

if  	cmd == "r_cs"	:	print	(r_cs(p1,p2))
elif	cmd == "s_rc"	:	print	(s_rc(p1,p2))
elif	cmd == "c_rs"	:	print	(c_rs(p1,p2))
else	            	:	print	("error")

print	("")

Python がよくわかっていないので,いろいろなエラーが…
PHP から Python の呼び出し コマンドライン引数
https://mish.myds.me/…/r_cs/5/

弦,矢,半径

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.