cara mengambil input dinamis dalam 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.\n")
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.\n")
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:\nA = ", a)
print("B = ", b)
Sleepy Seal