Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

basic python. loading data from text files and squaring them ==================== aaa.txt test a line 1 3,6,8,99,-4,0.6,8 0,9,7,5,7,9,5 2,2,2,2,2,2,5 7,5,1,2,12,8,0.9 ===================== bbb.txt test b line

basic python. loading data from text files and squaring them

image text in transcribed

====================

aaa.txt

test a line 1 3,6,8,99,-4,0.6,8 0,9,7,5,7,9,5 2,2,2,2,2,2,5 7,5,1,2,12,8,0.9 =====================

bbb.txt

test b line 1 1,2,3,4,5,6,7,8 55,0,90,09,1,2,3, 8,9,7,6,8,7,6 3,43,5,8,2,4,1

======================

def mi_func(P): f=open(P, 'r') first = f.readline() restlines= f.readlines() f.close() return first, restlines

afirst,arest = mi_func('aaa.txt') bfirst,brest = mi_func('bbb.txt')

print(arest) print(brest)

################## #convert a rest into a float here #convert b rest into a float here #################

p=[i**2 for i in arest] #square each element of a rest c=[i**2 for i in brest] #square each element of b rest print(p) print(c)

=============================================================

basic python. multiplying data from a text file text available at bottom to copy and paste seqwet Last Checkpoint: Last Wednesday at 7:15 PM (autosaved) a Notepad File Edit FormatView Help test a line 1 3,6,8,99,-4,0.6,8 0,9,7,5,7,9,5 2,2,2,2,2,2,5 7,5,1,2,12,8,0.9 View nsert Cel Kene WidgetsHelp afirst arest def mi_func(P): f-open(P, ' first - f.readlineO restlines- f.readlines(O f.close() return first, restlines bbb- Notepad File Edit Format View Help afirst,arest mifunc( aaa.txt') bfirst,brest - mi_func( bbb.txt') test,4,5,6,718 bfirst print (arest) print (brest) 55,0,90,09,1,2,3, 8,9,7,6,8,7,6 3,43,5,8,2,4,1 brest #convert a rest into a float here #convert b rest into a float here #square each element of a rest #square each element of b rest p=[i""2 for c-li."2 for print(p) print(c) i in arest] brest] i in please add code here ['3,6,8,99,-4,0.6,8 ', e,9,7,5,7,9,5 ', 2,2,2,2,2,2,5 , ['1,2,3,4,5,6,7,8 , 55,e,90,09,1,2,3, ', 8,9,7,6,8,7,6 ', 3,43,5,8,2,4,1 make any changes you TypeError Traceback (most recent call last) python-input-25-d83d49c3b17c> in () wish here to make it possible to print p and c 20 21 #square each element of a rest square each element of b rest > 22 p-[1""2 for i in arest] 23 c-i*2 for i in brest] 24 print (P) where p is arest except every element is squared python-input-25-d83d49c9b17c> in listcompX-8) 20 21 22 p=[i*"2 23 c=[i'*2 for 24 print(P) Square each element of a rest #square each element of b rest for i in arest] brest] > i in TypeError: unsupported operand type(s) for ** or pow) tr and 'int where c is brest except every element is squared

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions