-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh2_exercise.py
More file actions
83 lines (67 loc) · 1.45 KB
/
Ch2_exercise.py
File metadata and controls
83 lines (67 loc) · 1.45 KB
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
# Example
x = int (input('What is the meaning of life?'))
if x == 42:
print('Correct!')
if x > 42:
print('Too high :(')
else:
print('Too low :(')
x = int (input('What is the meaning of life?'))
if x == 42:
print('Correct!')
elif x > 42:
print('Too high :(')
else:
print('Too low :(')
# Exercise 1
print(f'\nExercise 1: a, b, c\n')
# Exercise 2
print(f'Exercise 2')
usern = input(f'Give me an integer: ')
if int(usern) % 2 == 0:
print(f'{usern} is an even number\n')
else:
print(f'{usern} is an odd number\n')
# Exercise 5
print(f'Exercise 5')
def f(x,y):
if x != 0 and y == 0:
return(f'The result is infinite...')
elif x == 0 and y == 0:
return(f'Indeterminate form')
else:
return(x/y)
a = int(input(f'Dividend: '))
b = int(input(f'Divisor: '))
print(f'{f(a,b)}\n')
# Exercise 7
print(f'Exercise 7')
def nand(x,y):
if x and y:
return False
else:
return True
print(nand(True,True))
print(nand(True,False))
print(nand(False,True))
print(nand(False,False))
def nor(x,y):
if not x and not y:
return True
else:
return False
print(nor(True,True))
print(nor(True,False))
print(nor(False,True))
print(nor(False,False))
def xnor(x, y):
if x and y:
return True
elif not x and not y:
return True
else:
return False
print(xnor(True,True))
print(xnor(True,False))
print(xnor(False,True))
print(xnor(False,False))