示例#1
0
#Start a new Python module by defining a function that
#supplies a default string value to its argument
def bark(pet='A Dog'):
    print(pet, 'Says WOOF!')


#Next, add two more function definitions that also supply
#default string values to their arguments
def lick(pet='A Dog'):
    print(pet, 'Drink water')


def nap(pet='A Dog'):
    print(pet, 'Sleeps In The Sun')


#Start a new Python script with a statement to make
#individual "dog" module functions available
from dog import bark, lick, nap

#Next, call each function without supplying an argument
bark()
lick()
nap()

#Now, call each function again and pass an argument value
#to each then save the file
bark('Pooch')
lick('Pooch')
nap('Pooch')
示例#2
0
# mylist = []
# for i in range(len(list)):
#     low = min(list)
#     list.remove(low)
#     mylist.append(low)
#print(mylist)

###
# def test_recipe(food_1, food_2):
#     recipe = food_1 + food_2
#     print(recipe)
#     return "The ingredients are " + food_1 + " and " + food_2 +"."
# food_1 = "egg"
# food_2 = "milk"
# print(test_recipe(food_1, food_2))

###
# def F(n):
#     if n == 0:
#         return 0
#     elif n == 1:
#         return 1
#     else:
#         return F(n-1)+F(n-2)
# n = 10
# print(F(n))

###
import dog
dog.bark(3)
示例#3
0
from dog import bark, lick, nap

bark()
lick()
nap()

bark('\nPooch')
lick('Pooch')
nap('Pooch')
示例#4
0
import dog
dog.bark()
#instead of importing the entire program we can import only the neccessary 
#functions using the from import(command)

from dog import bark,lick,nap

bark()
lick()
nap()

#try it with entering a parameter

bark("Pooch")
lick("Pooch")
nap("Pooch")

示例#6
0
from dog import bark, lick, nap

bark()
lick()
nap()
示例#7
0
#Next, add two more function definitions that also supply
#default string values to their arguments
def lick(pet='A Dog'):
    print(pet, 'Drink water')


def nap(pet='A Dog'):
    print(pet, 'Sleeps In The Sun')


#Start a new Python script with a statement to make
#individual "dog" module functions available
from dog import bark, lick, nap

#Next, call each function without supplying an argument
bark()
lick()
nap()

#Now, call each function again and pass an argument value
#to each then save the file
bark('Pooch')
lick('Pooch')
nap('Pooch')

#Start another Python script by making all "dog" module
#functions available
from dog import *

#Then, request the user enters a name to overwrite the
#default argument value
示例#8
0

from dog import color
print(color)

from dog import bark
bark(6)
示例#9
0
import dog
n = int(input("How many times do you want the dog to bark? "))
print(dog.color)

print(dog.bark(n))
示例#10
0
import dog
print(dog.color)
dog.bark(4)
示例#11
0
import dog

print(dog.color)
dog.bark(5)