Skip to content

Commit 9c298e6

Browse files
author
Khesualdo Condori
committed
Added different methods of input
1 parent 9b2d54e commit 9c298e6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sampleMethodsInput.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Example input:
2+
# 5
3+
# 1 2 3 4 5
4+
# Example Output: n = 5, data = [1, 2, 3, 4, 5]
5+
n, data = input(), [int(i) for i in input().strip().split()]
6+
7+
# How to take input from multiple lines
8+
# Will take input until sees a blank line (sentinel)
9+
# Example input:
10+
# 1 2 3
11+
# 4 5
12+
# Example Output: user_input = '1 2 3 4 5'
13+
sentinel = ''
14+
user_input = '\n'.join(iter(input, sentinel)).replace('\n', ' ')
15+
16+
# Example input:
17+
# 1 2 3 4
18+
# Example Output: var1 = 1, var2 = 2, var3 = 3, var4 = 4, such that var1, var2, var3, var4 are of type string
19+
var1, var2, var3, var4 = input().split()
20+
21+
# Example input:
22+
# 1 2 3 4
23+
# Example Output: var1 = 1, var2 = 2, var3 = 3, var4 = 4, such that var1, var2, var3, var4 are of type int
24+
var1, var2, var3, var4 = map(int, input().split())
25+
26+
# Example input:
27+
# 1 2 3
28+
# 1 2 3
29+
# ...
30+
# 1 2 3
31+
while True:
32+
try:
33+
34+
var1, var2, var3 = map(int, input().split())
35+
36+
except EOFError:
37+
break

0 commit comments

Comments
 (0)