Friday, June 17, 2022

Swicth via Python 3.8 dictionary Ubuntu 20.04

 (.env) boris@boris-All-Series:~/VOTING$ python --version

Python 3.8.10

(.env) boris@boris-All-Series:~/VOTING$ cat replaceSwitch.py

# Switcher is dictionary data type here

def number_to_string(argument):

    switcher = {

        0: "zero",

        1: "one",

        2: "two",

        3: "three",

        4: "four",

        5: "five",

    }

    return switcher.get(argument, "nothing")

 

if __name__ == "__main__":

    argument = int(input("digit = ")) 

    print(number_to_string(argument))

(.env) boris@boris-All-Series:~/VOTING$ python3 replaceSwitch.py

digit = 0

zero

(.env) boris@boris-All-Series:~/VOTING$ python3 replaceSwitch.py

digit = 2

two

(.env) boris@boris-All-Series:~/VOTING$ python3 replaceSwitch.py

digit = 1

one

(.env) boris@boris-All-Series:~/VOTING$ python3 replaceSwitch.py

digit = 5

five































No comments:

Post a Comment