Computer Science, asked by zinabby2220, 11 months ago

Given the program
from scitools.StringFunction import
StringFunction
import sys
formula = sys.argv[1]
f = StringFunction(formula)
print f(2)
Will this input work?
Unix/DOS > python function.py ‘t**2’

Answers

Answered by poojan
0

Yes! It works and results 4 as an output.

Program :

from scitools.StringFunction import  StringFunction

import sys

formula = sys.argv[1]

f = StringFunction(formula)

print f(2)

Output :

4

Explanation :

  • As 0th index command line argument will be the program name itself, we will take input 't**2' as 1st command line argument.

  • StrinfFunction() is an in-built function that takes a mathematical statement as an input and processes it further.

  • On passing the argument to StringFunction() and storing it in variable, we send an argument by variable function thereby, that replaces the unknown variable on the mathematical statement taken as an input and returns the computed value as output.

  • So, in the mathematical statement y**2 (y²), y is replaced by the passed value too and gets computed, resulting 4.

  • Print it separately, or place the calling function in the print statement itself. That's it.

Learn more :

  • Advantages of Programming in python

        brainly.in/question/11007952

  • Indentation is must in python. Know more about it at :

        brainly.in/question/17731168

Similar questions