Data types and variables

← Back to assignments

ungraded
# Google is encouraged. Type what you find, do not paste it. # ---- Part 1: numbers ---- def square(n): """Return n multiplied by itself. square(5) → 25 square(-3) → 9 Search: "python power operator". """ raise NotImplementedError def average(a, b): """Return the mean of two numbers. average(2, 5) → 3.5 average(4, 4) → 4.0 Search: "python division float". """ raise NotImplementedError # ---- Part 2: strings ---- def last_char(text): """Return the last character of text. last_char("code") → e last_char("") → None (decide what to return for an empty string) Search: "python string index". """ raise NotImplementedError # ---- Part 3: conversion ---- def to_number(text): """Convert text to a number. to_number("42") → 42 to_number("3.5") → 3.5 Search: "python string to int". """ raise NotImplementedError def is_number(text): """Return True when text holds a valid number. is_number("42") → True is_number("-7") → True is_number("abc") → False Search: "python check if string is a number". """ raise NotImplementedError