Python Classroom
  • Introduction
  • About Python Classroom
  • Python Cloud Options
    • CS50 IDE
      • CS50 IDE Overview
      • CS50 IDE and Python
      • CS50 IDE Debugging
      • CS50 IDE Shortcuts
      • Linux Bash Shell
      • Vim Mode
        • Vim Tutorial
    • CS50 Sandbox
    • PythonAnywhere
    • Repl.it
  • Python Curriculum Map
    • Pedagogy
      • Python Professional Development
      • Teaching Tips
      • Assessment Tips
      • Rubrics
      • Activities
        • Picture Activity
        • Map Activity
        • Crossing the Bridge
        • NIM
        • Mastermind
        • Cards
          • Card Deck Algorithms
          • Sorting Cards
        • River Crossing
          • Jealous Boyfriends
          • Cannibals and Priests
          • Family
          • Police and the Thief
          • Humans and Monkeys
          • Moving Money
        • Crossing the River
        • Traveling Salesperson
        • Logic Problems
        • CIA Crack the Code
        • IQ Test
        • Puzzles
    • AP Computer Science Principles Framework
  • Python Philosphy
    • How to Practice Python
  • microbit
  • Turtle Graphics
    • Turtle Examples
    • Turtle Activities
    • Turtle Maze Problems
    • Turtle Graphics with loops
    • Turtle Snake
    • Turtle Graphics with Conditionals
  • Output
    • Output Examples
    • Output Mistakes
  • Variables
    • Variable Data Type Examples
    • Variable Role Examples
    • Variables Mistakes
    • Variables Problems
  • Math
    • Math Examples
    • Math Mistakes
    • Math Problems
    • Math Self Check
  • Input
    • Input Examples
    • Input Mistakes
    • Input Problems
  • Decisions
    • if
      • if Examples
      • if Mistakes
      • if Problems
    • if else
      • if else Examples
      • if else Problems
      • if / if else Problems
    • if elif else
      • if elif else Examples
      • if elif else Problems
    • nested if
      • nested if Examples
      • nested if Problems
    • Logical Operators
      • Logical Operators Examples
    • Adventure Game Project
  • Loops
    • while loop - count up
      • Examples
      • Problems
    • while loop - countdown
      • Examples
      • Problems
    • while loop - sentinel value
      • Problems
    • while loop - sentinel menu
      • Problems
    • for loop - range (one argument)
      • Examples
      • Problems
    • for loop - range (two arguments)
      • Problems
    • for loop - range (three arguments)
      • Problems
  • Lists
    • Lists - Numbers
      • Problems
    • Lists - Strings
      • Problems
      • Shopping Project
  • Dictionaries
  • String Methods
  • Functions
    • Variable Scope
    • Functions - no parameters
    • Functions - one parameter
    • Functions - return
    • Functions - lists
  • Files
  • Classes
    • Inheritance
  • Python Projects
    • Adventure Game
    • Restaurant Project
    • Trivia Game
    • Family Tree Project
  • Raspberry Pi
    • Raspberry Pi Models
    • Raspberry Pi Setup
  • Roblox
  • Glossary
Powered by GitBook
On this page

Was this helpful?

  1. Functions

Functions - return

def main():
  done = False
  while not done:
    print("Menu")
    print("D - Do Now")
    print("Q - Quit")
    print("e1 - Example1")
    print("e2 - Example2")
    print("e3 - Example3")
    print("p1 - Problem1")
    print("p2 - Problem2")
    print("p3 - Problem3")
    choice = input("Choice: ")
    if choice == "D":
        print("Do Now")
        base=int(input("Base?"))
        height=int(input("Height?"))
        donow(base,height)
    elif choice == "Q":
        print("Exiting Game!")
        done = True
    elif choice == "e1":
        base=int(input("Base?"))
        height=int(input("Height?"))
        area=e1(base,height)
        print(area)
    elif choice == "e2":
        base=int(input("Base?"))
        height=int(input("Height?"))
        length=int(input("Length?"))
        volume=e2(base,height,length)
        print(volume)
    elif choice == "e3":
        x1=int(input("x1?"))
        x2=int(input("x2?"))
        y1=int(input("y1?"))
        y2=int(input("y2?"))
        slope=e3(x1,x2,y1,y2)
        print(slope)

def donow(base,height):
  print (base*height*1/2)

def e1(base,height):
  return (base*height*1/2)

def e2(base,height,length):
  return (base*height*length)

def e3(x1,x2,y1,y2):
  return ((y2-y1)/(x2-x1))

main()
def main():
  done = False
  while not done:
    print("Menu")
    print("D - Do Now")
    print("Q - Quit")
    print("e1 - Example 1")
    print("e2 - Example 2")
    print("e3 - Example 3")
    choice = input("Choice: ")
    if choice == "D":
        print("Do Now")
        base=int(input("Base?"))
        height=int(input("Height?"))
        donow(base,height)
    elif choice == "Q":
        print("Exiting Game!")
        done = True
    elif choice == "e1":
        base=int(input("Base?"))
        height=int(input("Height?"))
        area=e1(base,height)
        print(area)
    elif choice == "e2":
        base=int(input("Base?"))
        height=int(input("Height?"))
        length=int(input("Length?"))
        volume=e2(base,height,length)
        print(volume)
    elif choice == "e3":
        x1=int(input("x1?"))
        x2=int(input("x2?"))
        y1=int(input("y1?"))
        y2=int(input("y2?"))
        slope=e3(x1,x2,y1,y2)
        print(slope)

def donow(base,height):
  print (base*height*1/2)

def e1(base,height):
  return (base*height*1/2)

def e2(base,height,length):
  return (base*height*length)

def e3(x1,x2,y1,y2):
  return ((y2-y1)/(x2-x1))
  
main()
PreviousFunctions - one parameterNextFunctions - lists

Last updated 6 years ago

Was this helpful?