Académique Documents
Professionnel Documents
Culture Documents
1 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
In [20]: #The eval function dynamically translates the text provided by the user i
nto an executable form that the program can process.
x1 = eval(input('Entry x1? '))
print('x1 =', x1, ' type:', type(x1))
Entry x1? 67
x1 = 67 type: <class 'int'>
Entry x2? 7.8
x2 = 7.8 type: <class 'float'>
Entry x3? "sayani"
x3 = sayani type: <class 'str'>
print(eval(input()))
In [18]: print(eval(input()))
5+4
9
a = True b = False
a = False b = False
2 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
3 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
if value < 0:
print("Too small")
elif value == 0:
print("zero")
elif value == 1:
print("one")
elif value == 2:
print("two")
elif value == 3:
print("three")
elif value == 4:
print("four")
elif value == 5:
print("five")
else:
print("Too large")
print("Done")
1
2
3
4
5
21 18 15 12 9 6 3
4 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
1
3
6
10
15
21
28
36
45
1
4
9
16
25
1 2 3 4 5 6 7 8 9 10
+----------------------------------------
1 | 1 2 3 4 5 2 | 2 4 6 8 10 3 | 3 6 9 12
15 4 | 4 8 12 16 20 5 | 5 10 15 20 25
5 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
In [24]: sum = 0
done = False;
while not done:
val = eval(input("Enter positive integer (999 quits):"))
if val < 0:
print("Negative value", val, "ignored")
continue; # Skip rest of body for this iteration
if val != 999:
print("Tallying", val)
sum += val
else:
done = (val == 999); # 999 entry exits loop
print("sum =", sum)
In [27]: a = 0
while a < 100:
print('*', end='')
a += 1
print()
************************************************************************
****************************
6 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
# Report result
print("Square root of", num, "=", root)
Enter number: 8
Square root of 8 = 2.8284271247461903
7 of 8 9/29/2022, 8:48 AM
Python Code http://localhost:8888/nbconvert/html/Python%20Code.ipynb?downlo...
In [43]: # Count to ten and print each number on its own line
def count_to_10():
for i in range(1, 11):
print(i)
print(rev([1, 2, 3, 4, 5, 6, 7]))
[7, 6, 5, 4, 3, 2, 1]
8 of 8 9/29/2022, 8:48 AM