Answered step by step
Verified Expert Solution
Question
1 Approved Answer
TypeError: can't multiply sequence by non-int of type 'float' Python program, I'm getting this error please help me know what i'm doing wrong. Exception in
TypeError: can't multiply sequence by non-int of type 'float' Python program, I'm getting this error please help me know what i'm doing wrong. Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__ return self.func(*args) File "/Users/Adhara/PycharmProjects/HelloWorld/venv/lib/LeibnizProgram.py", line 62, in radiusCalculation AreaCircle = LeibnizClass.LeibnizPIClass.areaC(f1, response2) # this function Calculate the Area of Circle File "/Users/Adhara/PycharmProjects/HelloWorld/venv/lib/LeibnizClass.py", line 23, in areaC AreaCircle=f1 * radius * radius TypeError: can't multiply sequence by non-int of type 'float' LeibnizClass.py class LeibnizPIClass: pi = 0.0 '''Please enter the number of values to be calculated for Pi:''' def __init__(self, user_input): '''comment''' denominator = 1 numerator = 4 counter = 0 while counter < user_input: nextterm = numerator/denominator * (-1) **counter self.pi += nextterm denominator += 2 counter += 1 def areaC(f1, radius): AreaCircle=f1 * radius * radius print("Area Circle= " + "%.2f" %AreaCircle) def CircleC(f1,radius): CircleCircumference=2 * f1 * radius print("Circle Circumference= "+ "%.2f" % CircleCircumference) def VolumeS(f1,radius): VolumeOfSphere=(4/3) * f1 * radius * radius print("Volume Of Sphere= " + "%.2f" %VolumeOfSphere)
LeibnizProgram.py
import tkinter import LeibnizClass # Define what happens when Exit button is clicked def leave(): window.destroy() def errorMessages(): """This function contains the reusable error messages.""" print("You entered an invalid value. You must enter a positive integer.") main() def ending(): """Allows the user to run the program again or terminate it.""" print(" " "Type A to run the program again. " "Press Enter to end the program.") runagain = input() if runagain == "A": main() def piCalculation(): """This function controls the main thread of the program.""" response = entry_field.get() try: user_input = float(response) except ValueError: error_result_lbl.configure(text = "You entered an invalid value for PI ") else: if user_input <= 0: error_result_lbl.configure(text="You entered an invalid value for PI") else: f = LeibnizClass.LeibnizPIClass(user_input) f1=f.pi #store the pi value to f1 output_lbl.configure(text = f.pi) def radiusCalculation(): response2 = radius_field.get() try: user_input1 = float(response2) except ValueError: error_result_rlbl.configure(text = "You entered an invalid value for radius") else: if user_input1 <= 0: error_result_rlbl.configure(text="You entered an invalid value for radius") else: f1 = LeibnizClass.LeibnizPIClass.pi AreaCircle = LeibnizClass.LeibnizPIClass.areaC(f1, response2) # this function Calculate the Area of Circle area_result_lbl.configure(text=AreaCircle) CircleCircumference = LeibnizClass.LeibnizPIClass.CircleC(f1, response2) circumference_result_lbl.configure(text = CircleCircumference) # this function Calculate the Circle Circumference VolumeOfSphere = LeibnizClass.LeibnizPIClass.VolumeS(f1, response2) # this function Calculate the Volume Of Sphere volume_result_lbl.configure(text = VolumeOfSphere) # Create a window object and give it a title window = tkinter.Tk() window.title("PI Calculator") window.geometry("600x600") # Create a label and and place it in a grid instruction_lbl = tkinter.Label(window, text="Enter the number of values to be calculated for PI:") instruction_lbl.place(x=10, y=10) # Create a text entry field entry_field = tkinter.Entry(window, width=10) entry_field.place(x=340, y=10) entry_field.focus() # Make an Enter button enter_btn = tkinter.Button(window, text="Go!", command = piCalculation) enter_btn.place(x=450, y=10) # Create a label and and place it in a grid pi_results_lbl = tkinter.Label(window, text="PI Value is:") pi_results_lbl.place(x=10, y=40) # Create an empty label for displaying the results output_lbl = tkinter.Label(window, text=" ") output_lbl.place(x=100, y=40) radius_lbl = tkinter.Label(window, text="Please enter positive integer for radius:") radius_lbl.place(x=10, y=70) go_btn = tkinter.Button(window, text="Go!", command = radiusCalculation) go_btn.place(x=380, y=70) radius_field = tkinter.Entry(window, width=10) radius_field.place(x=270, y=70) radius_field.focus() area_circle_lbl = tkinter.Label(window, text="Area of a Circle:") area_circle_lbl.place(x=10, y=100) area_result_lbl = tkinter.Label(window, text=" ") area_result_lbl.place(x=120, y=100) circumference_lbl = tkinter.Label(window, text="Circle Circumference:") circumference_lbl.place(x=10, y=130) circumference_result_lbl = tkinter.Label(window, text=" ") circumference_result_lbl.place(x=160, y=130) volume_lbl = tkinter.Label(window, text="Volume of Sphere:") volume_lbl.place(x=10, y=160) volume_result_lbl = tkinter.Label(window, text=" ") volume_result_lbl.place(x=140, y=160) error_lbl = tkinter.Label(window, text="ERROR MESSAGE:") error_lbl.place(x=10, y=210) error_result_lbl = tkinter.Label(window, text="") error_result_lbl.place(x=165, y=210) error_result_rlbl = tkinter.Label(window, text="") error_result_rlbl.place(x=165, y=2250) # Create an Exit button and place it in the frame exit_btn = tkinter.Button(window, text="Exit") exit_btn.place(x=10, y=300) reset_btn = tkinter.Button(window, text="Reset") reset_btn.place(x=70, y=300) # Draw the window and start the program window.mainloop()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started