Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: django pass list of fields to values 
Python :: numpy random entries not repeat 
Python :: python datetime make timezone aware 
Python :: how to adda vaslues to data frame 
Python :: scipy.stats.spearmanr 
Python :: How to change application icon of pygame 
Python :: reverse string in python without using function 
Python :: python integers 
Python :: get image image memeory size in url inpyton requests 
Python :: get all ForeignKey data by nesting in django 
Python :: Power Crisis 
Python :: Python Zigzag a matrix for dct 
Python :: Python NumPy transpose Function Syntax 
Python :: best time to buy and sell stock python 
Python :: matplotlib yaxis off 
Python :: interface in python 
Python :: ipywidgets label text color 
Python :: Run a Flask API from CMD 
Python :: how to combine number of excel files into a single file using python or pandas 
Python :: 20 minute timer with python 
Python :: speech to text 
Python :: aws django bucket setting 
Python :: float error python 
Python :: how to omit days pandas datetime 
Python :: get coordinates of an image from a pdf python 
Python :: python check if string contains number 
Python :: how to print values without space in python 
Python :: image deblurring python 
Python :: how to backspace in python 
Python :: symmetric_difference() Function of sets in python 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =