Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to take dynamic input in python

import ast

def input_detect(s):
    return ast.literal_eval(input(s))

def swap(x, y):
    return y, x
aValid = 1
bValid = 1
a = input_detect("Enter an integer as a value for A: ")
if (str(type(a)) != "<class 'int'>"):
    print("Please take us seriously, we're watching you.
")
    aValid = 0
    while (aValid == 0):
        a = input_detect("Enter an integer as a  value for A: ")
        if str(type(a)) != "<class 'int'>":
            print("Please take us seriously, we're watching you.
")
            aValid = 0
        else:
            aValid = 1

# ! To be worked on:

b = input_detect("Now, Please enter the value for B: ")
print("A = " , a)
print ("B = ", b)

a, b = swap(a, b)

print("Now:
A = ", a)
print("B = ", b)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dynamic #input #python
ADD COMMENT
Topic
Name
9+9 =