File: test_logic_function.py

package info (click to toggle)
imediff 3.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: python: 6,397; sh: 904; xml: 336; makefile: 28
file content (49 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3
# vim:se tw=79 sts=4 ts=4 et ai fileencoding=utf-8 :

import sys
import termios


def getch():
    old_settings = termios.tcgetattr(0)
    new_settings = old_settings[:]
    # Enable canonical mode. See termios(3)
    new_settings[3] &= ~termios.ICANON
    try:
        # Change attributes immediately.
        termios.tcsetattr(0, termios.TCSANOW, new_settings)
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(0, termios.TCSANOW, old_settings)
    return ch


def yn0():
    print("\n0: enter 'y' or 'n': ", end="")
    ch = getch()
    if ch == "y":
        r = True
    else:
        r = False
    return r


def yn1():
    print("\n1: enter 'y' or 'n': ", end="")
    ch = getch()
    r = ch == "y"
    return r


# NO `return ch == "y"` like C

if yn0():
    print("\nTRUE\n")
else:
    print("\nFALSE\n")

if yn1():
    print("\nTRUE\n")
else:
    print("\nFALSE\n")