Python Forum

Full Version: Random Expression Creator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Overall My program is good. But I am having trouble figuring out how to do a few things. I could really use some help. I need to know how to fix my parenthesis appearing above all the other text and make it display inside the expression as well as get rid of the "None" text appearing in my expression. The last thing is I don't know how to make my answer variable(line 43) = the answer to the expression. By the way, the outcome is when I took out line 43. Thank you for your help! Smile
import time
from tkinter import *
import random
answer_input = 0
answer = 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.")
print(' ')
Random_Number1 = random.randint(0, 100)
Random_Number2 = random.randint(0, 100)
Random_Number3 = random.randint(0, 100)
Random_Number4 = random.randint(0, 100)
Random_Number5 = random.randint(0, 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 = print('(')
    ParenthesisB1 = print(')')
else:
    ParenthesisA1 = print(' ')
    ParenthesisB1 = print(' ')
if PE2 == 1:
    ParenthesisA2 = print('(')
    ParenthesisB2 = print(')')
else:
    ParenthesisA2 = print(' ')
    ParenthesisB2 = print(' ')
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 = 
input = answer_input
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. ( ) ( ) None 64 SR3 * 23 None P5 - None 63 SR1 / 57 None SR5 * 1 P5 Nice Work! You Really Know Your Stuff.
Using string's format method will save you a lot of trouble with formatting your strings. There are plenty of resources online, as well as a tutorial on our forum.
You are also not using input (line 44) the right way, see this or this.
Use string formatting to construct the string you want to display, and you can also save it to a variable to compare against. If I understood your intentions correctly, that is...
You are getting None because the print function returns None.