+ 1

Help me with printing given number

Given any 5 numbers(not in order) as inputs, how do I print only two numbers that I want?

6th Dec 2022, 6:30 PM
Shilling Ndivho
Shilling Ndivho - avatar
6 Answers
+ 5
ComputerGuru 》ShillingN , to get multiple values for the input in one go, we can also do it like this: #try to use this input: 2 5 7 4 11 (numbers are separated by a space) nums = list(map(int, input().split())) print(nums) # output will be: [2, 5, 7, 4, 11] how is it working: > we take the input as a string by using input() > the input string will then be split at each space position by using split() > each of these splitted tokens will be taken be the map() function, and an int conversion will by applied by using int > finally the result of all these nested steps (the map object) will be converted to a list by using the list constructor
6th Dec 2022, 7:45 PM
Lothar
Lothar - avatar
+ 2
</CODER> you cannot use numbers as variable name. ComputerGuru 》ShillingN Yes there are lists in Python and it's easy to use them. The following code will take 5 numbers from user input, then prints the first and last one. numbers = [] for _ in range(5): numbers.append(int(input())) print(numbers[0]) print(numbers[-1])
6th Dec 2022, 7:06 PM
Tibor Santa
Tibor Santa - avatar
+ 1
If I understood the task correctly: 1 = int(input()) 2 = int(input()) 3 = int(input()) 4 = int(input()) 5 = int(input()) print = (variables you want) If I misunderstood you, please tell me so
6th Dec 2022, 6:58 PM
</CODER>
</CODER> - avatar
+ 1
O! Thank you! I made a mistake. Thanks for the fix and your code. It's really compact!
6th Dec 2022, 7:08 PM
</CODER>
</CODER> - avatar
0
</CODER> Thanks It seems you did but isn't there a short way of storing the inputs in like Lists or Arrays?🤷‍♂️
6th Dec 2022, 7:00 PM
Shilling Ndivho
Shilling Ndivho - avatar
0
I think no. But I will think. Please give me time
6th Dec 2022, 7:04 PM
</CODER>
</CODER> - avatar