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


沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...