-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_example.py
154 lines (101 loc) · 2.99 KB
/
func_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
# coding: utf-8
# # example of function
# In[ ]:
def double_one():
fix1 = input()
fix2 = input()
print(fix1, fix2, sep="\n")
return
double_one()
# In[ ]:
# function has a string parameter with default argument
def title_msg(msg="hello"):
return msg
title_msg(input("Enter msg : "))
# In[ ]:
var = title_msg(input("What is the title ? "))
print("Your title is ",var)
# In[ ]:
def bookstore(book,price):
# function code here
return book,price
z = bookstore(input("Entry book name : "),input("Entry price of book : "))
x = bookstore(input("Entry book name : "),input("Entry price of book : "))
print(z)
print(x)
# In[ ]:
def function_that_prints():
print("I printed")
def function_that_returns():
return "I returned"
f1 = function_that_prints()
f2 = function_that_returns()
print ("Now let us see what the values of f1 and f2 are")
print (f1)
print (f2)
# RecursionError: maximum recursion depth exceeded in comparison
# In[ ]:
def say_hi(para1):
print(para1)
# return para1
#
say_hi("hello")
p = say_hi("test")
print(p)
x = say_hi("a")
z = say_hi("toy")
c = say_hi("double")
# getting None type value because function cannot pass print value instead of "return" value.
print(c)
print(x)
print(z)
# ## Program: bird_available
# The program should ask for user to "input a bird name to check for availability" and print a statement informing of availability
# ### create this program with a Boolean function `bird_available()`
# - has parameter that takes the name of a type of bird
# - for this exercise the variable `bird_types = 'crow robin parrot eagle sandpiper hawk piegon'`
# - return `True` or `False` (we are making a Boolean function)
# - call the function using the name of a bird type from user input
# - print a sentence that indicates the availablity of the type of bird checked
# In[ ]:
# [ ] create function bird_available
def bird_available():
bird_types = 'crow robin parrot eagle sandpiper hawk piegon'
return name in bird_types
# [ ] user input
name = input("Enter bird name : ")
# [ ] call bird_available
z = bird_available()
# [ ] print availbility status
print(name,"availbility status",z)
# In[ ]:
# example
# function with exception handling
def order():
while True:
try:
count = int(input("How many order ? "))
return count
except Exception as e:
print("Kindly enter in numbers")
print("Example :- 1, 2, 3, 4, 5 etc..")
finally:
print("Thanks to choose our service.")
choice = order()
print(choice," will be ordered soon!!")
# In[10]:
# example
def order():
try:
count = int(input("How many order ? "))
return count
except Exception as e:
print("Kindly enter in numbers")
print("Example :- 1, 2, 3, 4, 5 etc..")
finally:
print("Thanks to choose our service.")
choice = order()
if choice is not None:
print(choice, " will be ordered soon!!")
# In[ ]: