Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python 1. The following lines of code read numbers from the user and compute their average. Sort the lines into a working python script.

in python

1. The following lines of code read numbers from the user and compute their average. Sort the lines into a working python script. Ignore tabbing, only the order matters.

for i in range(0,5):

X=[]

print("Result is",sum(X)/len(X))

X.append(int(input("Enter Value: ")))

2.Fill in the blanks to complete the output of the below Python program.

def secret(n): p = 1 i = 0 while p <= n: print("p=",p) print("i=",i) p=p*2 i=i+1 r=i-1 print("r=",r) return r secret(10)

Complete the below output

Complete the below output

p= i= p= i= p= i= p= i= r=

3.What Data Type is returned by the input command?

String

Integer

Float

Audio File

4.

Match the loop with the description of what it computes.

x=0

for a in L:

x+=a

print("Answer:",x)

i=0

a=L[0]

while i < len(L):

if a <= L[i]:

a=L[i]

i+=1

print("Answer:",a)

q=L[0]

for m in L:

if m < q:

q=L[i]

print("Answer:",q)

i=0

q=0

while i < len(L):

q=q+L[i]/len(L)

i+=1

print("Answer:",q)

A.

The minimum element in the list L

B.

The sum of elements in the list L.

C.

The maximum of elements in the list L.

D.

The average of all element in the list L.

5.

The lines of code for the following function are out of order. Put the code in the correct order. Ignore tabbing.

The below comments explain how the function should work.

# This function computes the GCD. # The GCD(a,b) is the largest number # that divides both a and b evenly # Mathematically, it is defined below. # gcd(a,0)=a# gcd(a,b)=gcd(b,a%b) # for example gcd(30, 20) = 10 since 30/10=3 and 20/10=2

return a

b=y

a=b

def gcd(a,b):

while b > 0:

x = a // b

y = a-x*b

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

Know how to use reservations systems to inventory demand.

Answered: 1 week ago