Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Expression Creator
#1
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.
Reply
#2
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...
Reply
#3
You are getting None because the print function returns None.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wanted to tag azure resources with creator name raham3406 0 1,423 Apr-25-2021, 02:24 PM
Last Post: raham3406
  Pass results of expression to another expression cmdr_eggplant 2 2,238 Mar-26-2020, 06:59 AM
Last Post: ndc85430
  List creator acmichelman 4 4,132 Sep-04-2017, 09:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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