{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# scrivere funzione valore assoluto" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def valore_assoluto(x):\n", " if x < 0:\n", " return -x\n", " else:\n", " return x" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "valore_assoluto(-5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#def divisibile(x, y):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def divisibile(x, y):\n", " if x % y == 0:\n", " return True\n", " else:\n", " return False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# funzione che mi dice se f è un triangolo e poi mi dice che triangolo è" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def isTriangolo(a, b, c):\n", " return 0.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "isTriangolo(1, 2, 4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangolo(a, b, c):\n", " isTriangolo = a+b>c and a+c>b and b+c>a\n", " return isTriangolo" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangolo(2, 4, 5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangolo(a, b, c):\n", " isTriangolo = a+b>c and a+c>b and b+c>a\n", " if a+b>c and a+c>b and b+c>a:\n", " print('Triangolo')\n", " else:\n", " print('I tre interi non corrispondono a un triangolo valido')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangolo(2, 4, 5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangolo(a, b, c):\n", " isTriangolo = a+b>c and a+c>b and b+c>a\n", " if isTriangolo:\n", " if a==b and b==c:\n", " print('Equilatero')\n", " else:\n", " print('Altro')\n", " else:\n", " print('I tre interi non corrispondono a un triangolo valido')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangolo(2, 3, 5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangolo(a, b, c):\n", " isTriangolo = a+b>c and a+c>b and b+c>a\n", " if isTriangolo:\n", " if a==b and b==c:\n", " print('Equilatero')\n", " elif a==b or a==c or b==c:\n", " print('Isoscele')\n", " else:\n", " print('Scaleno')\n", " else:\n", " print('I tre interi non corrispondono a un triangolo valido')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangolo(3, 3, 3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangoloInput():\n", " a=input(\"inserisci un intero positivo per il lato a: \")\n", " b=input(\"inserisci un intero positivo per il lato b: \")\n", " c=input(\"inserisci un intero positivo per il lato c: \")\n", " return 0.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangoloInput()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangoloInput():\n", " a=input(\"inserisci un intero positivo per il lato a: \")\n", " b=input(\"inserisci un intero positivo per il lato b: \")\n", " c=input(\"inserisci un intero positivo per il lato c: \")\n", " dati_corretti=a.isdecimal() and b.isdecimal() and c.isdecimal()\n", " return dati_corretti" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangoloInput()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cheTriangoloInput():\n", " a=input(\"inserisci un intero positivo per il lato a: \")\n", " b=input(\"inserisci un intero positivo per il lato b: \")\n", " c=input(\"inserisci un intero positivo per il lato c: \")\n", " dati_corretti=a.isdecimal() and b.isdecimal() and c.isdecimal()\n", " if not dati_corretti:\n", " print(\"I dati inseriti contengono un errore\")\n", " print(a,b,c)\n", " else:\n", " a=int(a)\n", " b=int(b)\n", " c=int(c)\n", " cheTriangolo(a, b, c)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cheTriangoloInput()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }