Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in Pycharm
#1
I'm using Pycharm as a Python IDE. Is it advisable to do so?
I wrote a program and it gives me the following error messages (the code works, Pycharm says its a warning and a weak warning)

Error:
Name 'length' can be undefined Name 'n' can be undefined Multi-step list initialization can be replaced with a list literal
My code is (if required to help me):
numerator = float(input("Enter numerator: "))
denominator = float(input("Enter denominator: "))

numerator = int(round((numerator * 100 / denominator), 0))
denominator = 100

numbers_list = []
numbers_list.append(numerator)
numbers_list.append(numerator - 1)

sum_is_1 = False
difference_is_0 = False

test_number_1 = (numerator / 100) + ((numerator - 1) / 100)

doubling = 1

while not sum_is_1 and not difference_is_0:
    length = len(numbers_list)
    fractions_total = 0
    doubling = doubling * 2
    for i in range(length):
        numbers_list[i] = numbers_list[i] * 2
    for i in range(length - 1):
        numbers_list.insert(i + 1, numbers_list[i] - 1)
    length = len(numbers_list)
    for i in range(length):
        fractions_total = fractions_total + numbers_list[i] / (100 * doubling)
    test_number_2 = fractions_total
    if fractions_total >= 1:
        sum_is_1 = True
    difference = abs(test_number_1 - test_number_2)
    test_number_1 = test_number_2
    if difference <= 0.0001:
        difference_is_0 = True

print("For fraction " + str(numerator / denominator) +
      ", we can construct fractions <= " + str(numerator / denominator) +
      " such that their sum = 1")

print()

print("The list of numbers that had to be created")
print(numbers_list)

print()

print("the fractions are: ")
for i in range(length):
    print(numbers_list[i] / (100 * doubling))

print()

sum_1 = 0
for i in range(length):
    sum_1 = sum_1 + numbers_list[i] / (100 * doubling)
    sum_2 = sum_1 + numbers_list[i + 1] / (100 * doubling)
    if sum_2 >= 1:
        n = i + 1 # excluded
        break

sum_1 = 0
for i in range(n):
    sum_1 = sum_1 + (numbers_list[i] / (100 * doubling))
other_fraction = round(1 - sum_1, 5)

print("The fractions are: ")
for i in range(n):
    print(numbers_list[i] / (100 * doubling))
print(other_fraction)
What I intend to do is start off with a fraction. Say 3/10. We get to the next smaller fraction 2/10. Then I multiply both fractions by 2/2 = 1 and we get 6/20, 4/20. I can then get an in-between fraction 5/20. I repeat the process. I add these fractions up and check if the sum >= 1.
Reply


Messages In This Thread
Error in Pycharm - by Hudjefa - Oct-02-2024, 08:34 AM
RE: Error in Pycharm - by deanhystad - Oct-02-2024, 09:13 PM
RE: Error in Pycharm - by Hudjefa - Oct-09-2024, 02:45 AM
RE: Error in Pycharm - by deanhystad - Oct-09-2024, 08:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,365 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Pycharm error zuri 1 1,053 Nov-01-2023, 03:38 PM
Last Post: deanhystad
  PyCharm Error? coder_sw99 4 2,829 Sep-24-2021, 06:16 PM
Last Post: Yoriz
  Keep getting Session management error when running imshow in pycharm pace 0 2,842 Mar-25-2021, 10:06 AM
Last Post: pace
  REGEX Install Error in PyCharm charlesauspicks 1 3,467 May-14-2020, 08:10 PM
Last Post: buran
  Traceback error in PyCharm but not in other IDEs? devansing 7 8,526 Mar-05-2020, 11:27 AM
Last Post: buran
  Error in importing package in pycharm fullstop 0 2,821 Dec-12-2019, 04:03 PM
Last Post: fullstop
  can't assign to literal error in pycharm ryder5227 2 3,731 Oct-07-2019, 08:57 PM
Last Post: Bmart6969
  Weird error in pycharm TheRedFedora 1 3,308 Mar-11-2018, 09:01 PM
Last Post: Larz60+
  python turtle module in pycharm error sajley 2 14,203 Dec-12-2016, 08:52 PM
Last Post: sajley

Forum Jump:

User Panel Messages

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