저는 pyhon을 처음 접했습니다. 함수 목록이있는 txt 파일을 읽은 다음 읽은 순서대로 해당 함수를 실행하는 프로그램을 작성하는 방법을 도와주세요. 파일의 다른 기능은 다음과 같습니다.
add (x) → 정수 더하기; Mult (x) → 정수의 곱셈; SQR (X) → 정수의 sqrt.
x=input('enter the value of x: ')
mylist = []
with open("file_commands.txt","r") as fcommand:
lines = fcommand.readlines()
for m in lines[0:]:
mylist.append(m.split()[0])
for l in mylist:
if (l=='add(x) '):
print('addition of the integers:', add (int(x) ))
elif (l=='Mult(x)'):
print('multiplication of the integers:', Mult(int(x)) )
else:
print('sqrt of the integers.:', ZQR (int(x)) )
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다