| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Happy 23rd Birthday!\n"
- ]
- }
- ],
- "source": [
- "age = 23\n",
- "message = \"Happy \" + str(age) + \"rd Birthday!\"\n",
- "\n",
- "print(message)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Hello, Ada Lovelace!\n"
- ]
- }
- ],
- "source": [
- "# %load chapter_02/name.py\n",
- "first_name = \"ada\"\n",
- "last_name = \"lovelace\"\n",
- "full_name = first_name + \" \" + last_name\n",
- "\n",
- "message = \"Hello, \" + full_name.title() + \"!\"\n",
- "print(message)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "14"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "def sum(a,b):\n",
- " return a + b\n",
- "sum(12,2)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "['honda', 'yamaha', 'suzuki', 'ducati']\n",
- "['honda', 'yamaha', 'suzuki']\n",
- "\n",
- "A Ducati is too expensive for me.\n"
- ]
- }
- ],
- "source": [
- "motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati'] \n",
- "print(motorcycles)\n",
- "\n",
- "too_expensive = 'ducati'\n",
- "motorcycles.remove(too_expensive)\n",
- "print(motorcycles)\n",
- "print(\"\\nA \" + too_expensive.title() + \" is too expensive for me.\")\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']\n",
- "['dog', 'dog', 'goldfish', 'rabbit']\n"
- ]
- }
- ],
- "source": [
- "pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']\n",
- "print(pets)\n",
- "\n",
- "while 'cat' in pets:\n",
- " pets.remove('cat')\n",
- " \n",
- "print(pets)\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": 4
- }
|