2018年1月11日 星期四

Python: Input two integers in a single line

Python: Input two integers in a single line

Python Basic: Exercise-134 with Solution

Write a Python program to input two integers in a single line.
Sample Solution:-
items = [1, 2, 3, 4, 5]
squared = []
for i in items:
    squared.append(i**2)
items = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, items))

def multiply(x):
    return (x*x)
def add(x):
    return (x+x)
funcs = [multiply, add]
for i in range(5):
    value = list(map(lambda x: x(i), funcs))
    print(value)
# Output:
# [0, 0]
# [1, 2]
# [4, 4]
# [9, 6]
# [16, 8]
print("Input the value of x & y")
a1,a2=list(map(int, input().strip().split()))
print("The value of x & y are: ",a1,a2)

print("Input the value of x & y")
a3,a4=map(int, input().strip().split())
print("The value of x & y are: ",a3,a4)
========= RESTART: F:/Python_APSC/py-ex-basic-134.py ==========
[0, 0]
[1, 2]
[4, 4]
[9, 6]
[16, 8]
Input the value of x & y
12 45
The value of x & y are:  12 45
Input the value of x & y
56 78
The value of x & y are:  56 78
>>> 


沒有留言:

張貼留言

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...