Python: Quiz Part 3


1. What would be the output of this Python program when it runs?


	def calcTotal(x):
		total = x + x
		return total

	x = 2
	total = calcTotal(x)
	print(total)
	
  0
  1
  2
  4


2. What would be the output of this Python program when it runs?


	def total(one,two):
		result = one ** two
		return result

	result = total(2,3)
	print(result)
	
  2
  4
  6
  8


3. What would be the output of this Python program when it runs?


	def calcTotal(x):
		total = x + x
		return total

	for x in range(3):
		total = calcTotal(x)

	print(total)
	
  0
  1
  2
  4


4. What would be the output of this Python program when it runs?


	def calcTotal(x):
		total = x + x
		return total

	x = 2
	calcTotal(x)

	print(total)
	
  0
  1
  2
  4
  None of the above


5. What would be the output of this Python program when it runs?


	def calcTotal(x):
		total = x + x
		return total

	x = 2
	total = 0
	calcTotal(x)
	print(total)
	
  0
  1
  2
  4
  None of the above


6. What would be the output of this Python program when it runs?


	def calcTotal(x,total):
		total = x + x
		return total

	total=0
	for x in range(3):
		total = total + calcTotal(x,total)

	print(total)
	
  0
  2
  6
  8
  10


7. Write down on a piece of paper what you believe the output of this program would be and then check your answer below.


	def calcLoop():
		for x in range(2,6,2):
			print(x)

	for x in range(2,6,2):
		calcLoop()
	

 


8. What would be the output of this Python program when it runs?


	def calcLoop(x):
		x = x * 2

	x = 10
	calcLoop(x)
	print(x)
	
  0
  10
  20
  40
  None of the above


9. What would be the output of this Python program when it runs?


	def calcLoop(x):
		x = x * 2
		return x

	x = 5
	x = calcLoop(x)
	print(x)
	
  0
  5
  10
  20
  None of the above


10. Write down on a piece of paper what you believe the output of this program would be and then check your answer below.


	def calcLoop(x):
		for y in range(1,6):
			if y > 2:
				print(x)

	x = 5
	calcLoop(x)
	

 


11. What would be the output of this Python program when it runs?


	def calcLoop(z):
		x = 5
		y = 10
		result = ( x * z ) + y
		return x, y, result

	x, y, result = calcLoop(4)
	total = x + y + result
	print(total)
	
  0
  5
  10
  15
  25
  45
  None of the above


12. What would be the output of this Python program when it runs?


	def coupon(amount):
		amount = amount * .9
		return amount

	def mail_in_rebate(subtotal):
		subtotal = subtotal - 10
		return subtotal

	amount = 100
	subtotal = coupon(amount)
	due = mail_in_rebate(subtotal)
	print ("Due: %.2f" % due)
	
  0.00
  50.00
  70.00
  80.00
  90.00
  100.00
  110.00


13. What would be the output of this Python program when it runs?


	def coupon(amount):
		amount = amount * .9

	amount = 100

	coupon(amount)
	print (amount)
	
  0
  80
  90
  100
  110


14. What would be the output of this Python program when it runs?


	def coupon(amount):
		amount = amount - 10
		return amount

	amount = 100
	for x in range(3):
		amount = coupon(amount)
	print(amount)
	
  60
  70
  80
  90


15. What would be the output of this Python program when it runs?


	def calcTotal(a,b,c,d):
		x = b + c - 2
		y = d - x
		return x, y

	a = 2
	b = 4
	c = 6
	d = 10
	x, y = calcTotal(a,b,c,d)
	print (x,y)
	
  10 2
  2
  8
  8 2
  8 4
  6 2