@low prairie
Jeditwo Uploaded Some Code
I have been working on a python project today and I do not understand what is going wrong with my program.
My goal is to square the list three times and print it after every repetition, but after it goes through my function it returns as None instead of a list. I am trying to modify the original list, and not use the return statement.
Attachment: Squaring\_List.py
import time
def square(values):
#Creates a function called 'square' that takes a parameter called 'values'.
for i in range(len(values)):
values[i] = int(values[i] * values[i])
#takes a number from the list 'values', squares it, saves it in its old position, and moves onto the next one.
def main():
#Creates a function called 'main'.
n = int(input("How many numbers would you like to square? "))
values = list(range(1,n+1))
print("The original list is: ", values, ".")
for i in range(3):
print("The squared list is: ", square(values), ".")
main()
Attachment: Squaring\_List-output.txt
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
==== RESTART: D:\School\UMA\CIS 110\Python Projects\Week 5\Squaring_List.py ====
How many numbers would you like to square? 8
The original list is: [1, 2, 3, 4, 5, 6, 7, 8] .
The squared list is: None .
The squared list is: None .
The squared list is: None .
For safety reasons we do not allow file attachments.