The question is ask the user for 20 numbers one at a time, saves the numbers in list, and then printsa 2 column table with each number in the list entered in the first column and its square root in the second column. Each column should be 6 characters wide and the values in each column should have their decimal points aligned 3 places after the decimal point. i do not know how to do this only think i did is.

x = numbers
myList = []
for i in range(20):
    myList.append(input("Enter a number: "))

print(myList[i],math.sqrt(x))

:(

Recommended Answers

All 6 Replies

You need to make loop again for output.

To align columns in a table you can use the C style format specifiers with Python ...

mylist = [2, 5, 7, 4.5]

for item in mylist:
    # experiment with the format specifiers
    # eg. change 6.3 to 6.2 or 4.4 to see effects
    print("%6.3f  %6.3f" % (item, item*item))

''' my result -->
 2.000   4.000
 5.000  25.000
 7.000  49.000
 4.500  20.250
'''
import math

def numbers(nums):
   values = []
   for i in range(20):
     values.append(input("give me a num: "))
   return values


def main():
    values2 =[]
    for i in range(20):
     values2.append(math.sqrt(values))

    return values2

    print(values,end= """""",values2,= """""")

main()

i know there are abunch of mistakes here dont know how to fix them though.

i like the code above but it should ask the user for 20 numbers and makes them a list.

myList = []
num = eval(input("Enter num: "))
x = item
def main():
     
    for i in range(20):
        myList.append(input("give me a num"))
    return myList

print("%6.3f  %6.3f" % (x,math.sqrt(x)))

it says tem is not defined..

Where is tem used? And where it is given value?

i meant item not tem..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.