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


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...