{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 0\n", "(Prof. Carlos J. Costa)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solve the following questions without using decision statements (e.g. if) or loops (e.g. for)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**1)** Verify da data type of a specific variable." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**2)** Verify if a value is even" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**3)** Insert two numbers. Is the first is bigger than the second?" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**4)** Verify if one value is multiple of another" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**5)** Calculate the interest earn by an investor that invested an amount of capital of 200 during three years with an interest rate of 3%. \n", "(I= P\\*R\\*T)\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**6)** Capital that an investor obtained after investing an amount of capital of 200 during three years with an interest rate of 3%. (Compound interest)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**7)** Calculate your BMI (Body Mass Index) \n", " \n", "$BMI = mass (kg)/height^2 (m)$" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**8)** Calculate the Golden ration: \n", " \n", "$gr=(1+\\sqrt{5})/2$\n", "\n", "1. Solve the problem without using libraries\n", "2. Use module math (import math) and function sqr (math.sqrt)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**9)** Calculate the NPV (Net present value) of an investment, considering an initial investment of 10000, the following Cashflows 2000,3000, 4000, 4000 and 5000 and a discount rate of 10%.\n", "\n", "$NPV = \\sum_{t=1}^{n}\\frac{FV_{t}}{(1 + k)^{t}} – I$\n", "\n", "Where:\n", "\n", "FV = Future cost of the cash inflows,\n", "I = Initial Investment\n", "k = Discount rate equal to the owner’s cost of capital\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**10)** Ask the user to insert name and age. Calculate the birth year. Print a result saying the 'this person was born in.'\n", "1. Solve the problem without using modules and libraries\n", "2. Solve the problem using the date library from module datetime, as fallow:\n", " \n", "```python\n", "from datetime import date \n", "today = date.today() \n", "today.year \n", "```" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**11)** Ask the user to insert forenames, surnames. Create a new variable (name) with your complete name.\n", " \n", "Create the following variables: \n", " \n", "**nameBig** - all the characters of the name are capitalized \n", "**nameTitle** - only the first character of each name (word) is capitalized \n", "**nameSmall** - all the characters of the name are lowercase. \n", "**nameCapitalized** - only the first character of the first name is capitalized " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**12)** Use the following method to show in which character appears the first \"da\"\n", " \n", "```python\n", "str.find(sub,start,end)\n", "```\n", " \n", "What happens if the content of sub is not found in str?" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "#Code here\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }