-2

I wanted to make a program that adds the data from a while loop to a list, and computes the data. However, when I use .append, It returns nothing.

structure = input("Equation: ")
print("RANGE")
upper_lim = int(input("Upper limit: "))
value_i = int(input("The value of 'i': "))
nth = [""]
substitution = [""]

while value_i <= upper_lim and "i" in structure and "+" not in structure:
    substitution = print(structure.replace("i", "(" + str(value_i) + ")"))
    value_i += 1 
    nth.append(substitution)


while value_i <= upper_lim and "i" in structure:
    substitution = print(structure.replace("i", "(" + str(value_i) + ")"))
    value_i += 1
    nth.append(substitution)
    
print(nth)

It came out as:

   ['', None, None, None]

instead of something like:

   [numbers,numbers,numbersr]
Drew0429
  • 1
  • 2

1 Answers1

0
obj={"one":"1","two":"2"}
while i<5:
    substitution = print(obj) #obj will get printed
    i += 1 
    print("subs = ",substitution) #substitution will have None, since print from the above line will return None
    nth.append(substitution)

Print() displays the item but return None which gets saved in substitution variable

Sarthak
  • 380
  • 7
  • So why don't you also show the correct version? – B Remmelzwaal Mar 27 '23 at 15:15
  • Is there a way to gather the data from the substitution variable to a list? – Drew0429 Mar 27 '23 at 15:22
  • So if code inside `print()` is displaying correct output, then we can just remove the print and rest code will remain the same, so substitution variable will have the desired result and will get appended in the list? – Sarthak Mar 27 '23 at 15:39
  • Why do you think I want to print the output? Because I need it. If "None" is the printed result of the variable, Do you think the result is getting appended in the list? – Drew0429 Mar 28 '23 at 04:40