Quiz2 cs104 C Solutions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Student Name:

Student Number:
CS 104 – Spring 2022

QUIZ 2

1. (50pts) Assume we have a function defined as:

def sum_n_double(x,y):
return 2*(x+y)

What will be the result of the following expression? Please show result of each
term step by step.

sum_n_double(2+sum_n_double(1,2),3) + 10/sum_n_double(2,3)

Solution:
sum_n_double(2+6,3) + 10/10
sum_n_double(8,3) + 1
22 + 1
23

2. (50pts) Assume you own a portfolio of foreign currencies composed of USD (US
dollars) and EUR (euros). Write a function called totalAsset() that calculates and
outputs the value of your portfolio in TRY (Turkish liras). The function will take the
following arguments as input: amount of USD you own, USD to TRY conversion
rate, amount of EUR you own and EUR to TRY conversion rate.

For example: Assume you own 10 USD, conversion rate for USD to TRY is 14.
Additionally, you own 20 EUR and conversion rate for EUR to TRY is 15. The
function should return a result of 440 TRY.

def totalAsset(usdBalance, usdRate, euroBalance, euroRate):


total = usdBalance*usdRate + euroBalance*euroRate
return total

###
usdOwn = 10
usd2try = 14

euroOwn = 20
euro2try = 15

totalTry = totalAsset(usdOwn, usd2try, euroOwn, euro2try)


print("Total asset =", totalTry)

You might also like