{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "fd42952f-f89e-4660-86b9-7c753c1aa6b8", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "632b1bb8-4d5a-48ed-b606-798563f7288f", "metadata": {}, "source": [ "###
San Jose State University
Dep|artment of Applied Data Science

**DATA 200
Computational Programming for Data Analytics**

Spring 2024
Instructor: Ron Mak
" ] }, { "cell_type": "markdown", "id": "a032b427-fc88-4e31-a531-e678fa24d61e", "metadata": {}, "source": [ "# Number Translator, version 1" ] }, { "cell_type": "markdown", "id": "172ddfe7-9928-449c-a891-e51aed256876", "metadata": {}, "source": [ "#### Let's start with prompting the user for a number and checking its value. We don't know yet now to translate the number, so for now we'll write a placeholder function `translate()` that simply returns the number as a string." ] }, { "cell_type": "code", "execution_count": null, "id": "b47845d5-21b0-4d8d-9cae-bb75fae539d8", "metadata": {}, "outputs": [], "source": [ "def translate(n):\n", " \"\"\"\n", " Placeholder: Just return the number.\n", " \"\"\"\n", " return str(n)" ] }, { "cell_type": "code", "execution_count": null, "id": "a30a991b-0a4d-41d2-ac18-1ed6e700c6bd", "metadata": {}, "outputs": [], "source": [ "def prompt_for_number():\n", " \"\"\"\n", " Prompt the user for a number and return its value.\n", " \"\"\"\n", " good_number = False\n", " \n", " while not good_number:\n", " number = int(input('Number to translate? '))\n", " \n", " good_number = (0 <= number <= 999_999_999)\n", " if not good_number:\n", " print('Number must be between 1 and 999,999,999 inclusive. 0 to stop.')\n", " print()\n", " \n", " return number" ] }, { "cell_type": "code", "execution_count": null, "id": "bfa9ba15-716d-4eab-aaaa-2e68528efc5e", "metadata": {}, "outputs": [], "source": [ "n = prompt_for_number()\n", "\n", "# Loop to prompt for and translate numbers\n", "# until the user enters 0.\n", "while n > 0:\n", " print(translate(n))\n", " print()\n", " \n", " n = prompt_for_number()\n", "\n", "print()\n", "print('Done!')" ] }, { "cell_type": "code", "execution_count": null, "id": "79f059ba-a818-4285-8138-c8d642f16a07", "metadata": {}, "outputs": [], "source": [ "# (C) Copyright 2024 by Ronald Mak" ] }, { "cell_type": "code", "execution_count": null, "id": "cb7a6946-1b44-4aef-b0d5-8df5f9406eec", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.5" } }, "nbformat": 4, "nbformat_minor": 5 }