Python Forum
Expression Creator (Code for Answer)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expression Creator (Code for Answer)
#1
I made an expression creator. I only need one more line to fill in which is line 48. I would appreciate it if someone could give me code for line 48 and if any other code is needed just tell me and I can figure out where to put it. Also for lines 49, 51, and 52 I had it return what the variables were equivalent to. In the input it shows that both are equivalent to 0 but the coding on lines 53-58 return it as "answer" and "answer_input" to not be equivilent. Can someone tell me why that is. BTW the output is without line 48.
import time
from tkinter import *
import random
import math
answer_input = 0
answer = 0
ParenthesisA1 = 0
ParenthesisB1 = 0
ParenthesisA2 = 0
ParenthesisB2 = 0
sign_list = ['+','-','*','/']
power_list = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8',' ', 'SR0', 'SR1', 'SR2', 'SR3', 'SR4', 'SR5', ' ', ' ', ' ', ' ', ' ',]
Open_Parenthesis_list = random.randint(0, 1)
Open_Parenthesis_list2 = random.randint(0, 1)
Closed_Parenthesis = [')']
print("A random expression will be created that you must solve. *IMPORTANT: SR-Square Root, P2-Squared, P3-Cubed, SR2-Square root of, etc. Also if it says SR of a negative just leave the number as is without the SR")
print(' ')
Random_Number1 = random.randint(-100, 100)
Random_Number2 = random.randint(-100, 100)
Random_Number3 = random.randint(-100, 100)
Random_Number4 = random.randint(-100, 100)
Random_Number5 = random.randint(-100, 100)
Random_Sign1 = random.choice(sign_list)
Random_Sign2 = random.choice(sign_list)
Random_Sign3 = random.choice(sign_list)
Random_Sign4 = random.choice(sign_list)
Random_Sign5 = random.choice(sign_list)
Random_Power1 = random.choice(power_list)
Random_Power2 = random.choice(power_list)
Random_Power3 = random.choice(power_list)
Random_Power4= random.choice(power_list)
Random_Power5 = random.choice(power_list)
PE = Open_Parenthesis_list
PE2 = Open_Parenthesis_list2
if PE == 1:
    ParenthesisA1 = '('
    ParenthesisB1 = ')'
else:
    ParenthesisA1 = ''
    ParenthesisB1 = ''
if PE2 == 1:
    ParenthesisA2 = '('
    ParenthesisB2 = ')'
else:
    ParenthesisA2 = ''
    ParenthesisB2 = ''
print(ParenthesisA1, Random_Number1, Random_Power1, Random_Sign1, Random_Number2, ParenthesisB1, Random_Power2, Random_Sign2, ParenthesisA2, Random_Number3, Random_Power3, Random_Sign3, Random_Number4, ParenthesisB2, Random_Power4, Random_Sign4, Random_Number5, Random_Power5,)
answer = 
print(answer_input)
print(answer)
answer_input = input('Answer Here: ')
print(answer_input)
print(answer)
if answer_input == answer:
    print(' ')
    print('Nice Work! You Really Know Your Stuff.')
else:
    print(' ')
    print('Sorry... That is Incorrect')
Output:
A random expression will be created that you must solve. *IMPORTANT: SR-Square Root, P2-Squared, P3-Cubed, SR2-Square root of, etc. Also if it says SR of a negative just leave the number as is without the SR ( -92 P6 + 5 ) P2 * -38 SR4 + -19 P1 - 78 P6 0 0 Answer Here:
Output:
A random expression will be created that you must solve. *IMPORTANT: SR-Square Root, P2-Squared, P3-Cubed, SR2-Square root of, etc. Also if it says SR of a negative just leave the number as is without the SR ( -61 - 52 ) P7 / ( 33 SR4 * 5 ) P7 / -84 P5 0 0 Answer Here: 0 0 0 Sorry... That is Incorrect
Reply
#2
What have you tried?

You could modify the power symbols and use eval, though I bet you are expected to solve it some other way. I would go for a stack that could work through the symbols, applying powers, holding operators til they are needed, handling parentheses. The operator module would be handy for that, but if you are not allowed to use that you could do it with an if/elif structure for the different operators.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Answer for newbie, Sqlite3 Froger 2 864 Sep-27-2023, 05:33 PM
Last Post: noisefloor
  Coding answer for newbie cg3 2 1,165 Aug-05-2023, 12:17 PM
Last Post: jefsummers
  What am I doing wrong to not get the answer pav1983 7 3,725 Jun-25-2020, 08:53 PM
Last Post: ndc85430
  Need help with an assignment, not an answer. celtickodiak 4 2,952 Oct-01-2019, 02:04 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020