python chapter tests only 10 questions

profileHollywood4799
PYTHONCH5and7TESTFALL2020.docx

PYTHON CH 5 and 7 TEST NAME ___________________

(1)

def function1():

print ('PYTHON')

def message():

print('HELLO WORLD !!')

message()

function1()

message()

print ('DONE')

(2)

def function1(x, y):

x = 'BILL'

y = 45

print (x,y)

def main ():

x = ('SALLY')

y = 64

function1(x, y)

print (x,y)

main()

(3)

numberList = [43,21,50,4,50,35]

a = 50

if a in numberList:

print ('THE NUMBER IS IN THE LIST ')

print ('THE NUMBER IS AT POSITION' , numberList.index(a))

else:

print ('THE NUMBER IS NOT IN THE LIST')

(4)

numberList = [43,21,50,4,10,35]

listLength = len(numberList)

print ('the length of the list is ', listLength)

a = numberList [4] + numberList [2]

print ('A = ', a)

(5)

def function1(num1, num2):

x = num1 + num2

y = num1 * num2

return x, y

def function2 (a,b,c):

d = a + b + c

e = a * 2 + b

f = b + c + 4

return d, e, f

def main():

a = 7

b = 9

c = 11

n1, n2 = function1(a,b)

a,b,c = function2(12, 7, 15)

print (n1, n2)

print (a, b, c)

main()

(6)

numberList = [22, 45, 33, 17, 12, 10]

print (numberList[5], numberList[2])

numberList.sort()

print (numberList)

small = min(numberList)

large = max(numberList)

print ('THE SMALLEST NUMBER IN THE LIST IS ', small)

print ('THE LARGEST NUMBER IN THE LIST IS ', large)

(7)

myValue = 50

def show_value():

global myValue

myValue = 45

a = 10 + myValue

print (a, myValue)

def function2 ():

global myValue

myValue = 42

a = 100 - myValue

print (a, myValue)

show_value()

print (myValue)

function2()

print (myValue)

(8)

def function1():

num = 10

print(num)

def function2():

num = 15

a = num + 5

print (a, num)

def function3():

num = 25

a = num * 3

print(a, num)

function3()

function1()

function2()

(9)

def main():

a = [10,5,8,7]

n1= function1(a)

print (n1, a[2])

def function1(list1):

x = list1[2] + list1[0]

return x

def function2 (a,b,c):

d = a + b + c

e = a * 2 + b

f = b + c + 4

return d, e, f

main()

(10)

def main():

a = [10,5,8,7]

n1= function1(a)

print (n1, a[2])

function2 (a)

print (a)

def function1(list1):

x = list1[2] + list1[0]

return x

def function2 (c):

c[2] = 37

c[1] = 67

main()