-
Notifications
You must be signed in to change notification settings - Fork 9
/
ex_07_4.py
30 lines (24 loc) · 913 Bytes
/
ex_07_4.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
#!/usr/bin/python
#AUTHOR: alexxa
#DATE: 25.12.2013
#SOURCE: Think Python: How to Think Like a Computer Scientist by Allen B. Downey
# http://www.greenteapress.com/thinkpython/html/index.html
#PURPOSE: Chapter 7. Iteration
# Exercise 7.4
# Write a function called eval_loop that iteratively prompts the user,
# takes the resulting input and evaluates it using eval, and prints the result.
# It should continue until the user enters 'done', and then return the value of
# the last expression it evaluated.
def eval_loop():
result = None
while True:
string = str(input('Please enter your expression to evaluate. To finish enter "done".\n'))
if string != 'done':
result = eval(string)
print(result)
else:
break
print('The value of the last expression was {} .You entered "Done"'.format(result))
return result
eval_loop()
#END