I would like to create a program that calculates the values of A, B, C, and D by receiving the values of A, B, C, and D as inputs and then entering a simple four-factor operation using A, B, C, and D in the variable F. However, if you enter a regular operation expression such as A+B/C-D as input, "A+B*C-D" is recognized as a string, and even if you substitute this value later, you just output the string. Attempting to convert the data type of variable F through int results in an error stating that A to D is not defined. The code I wrote is as follows.
1) A=input() B=input() C=input() D=input() Enter F=input('A~D' operation>>') A=int(A) B=int(B) C=int(C) D=int(D)
def calculation(A,B,C,D): print (F)
calculation(A,B,C,D) c=input()
**After running) If A, B, C, D enter 1, 2, 3, 4 and A+B+C+D in F, the resulting value is a string of A+B+C+D. When F=int(F) is added, the following error occurs during execution.
================== RESTART: C:\Users\msshi\Desktop\test.py ==================a 1 2 3 4 Please enter the operation using A~D>>A+B+C+D Traceback (most recent call last): File "C:\Users\msshi\Desktop\test.py", line 10, in F=int(F) ValueError: invalid literal for int() with base 10: 'A+B+C+D'
How can I create a program where I put random numbers in A, B, C, D and put various four-way operations such as A+B-C/D or (A-B)/C+D in F values, and calculate them according to A, B, C, and D?
python3.6 function input
You have to do your homework by yourself.
We can do what we are thinking about as below.
a = 3
b = 4
eval('a + b')
7
© 2024 OneMinuteCode. All rights reserved.