-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQuestion30.py
More file actions
72 lines (66 loc) · 1.02 KB
/
Copy pathQuestion30.py
File metadata and controls
72 lines (66 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Question
# 30. Write a program to read a list of ‘n’ integers from the user. Create two new lists, one having all positive numbers and the other having all negative numbers. Print all three lists
# Code
x = []
n = 5
for e in range(n):
a = input(f"int {e}:\n")
while not a.replace('+','').replace('-','').isdigit():
a = input(f"int {e}:\n")
a = int(a)
x.insert(e, a)
lp = []
ln = []
for e in x: lp.append(e) if e > 0 else ln.append(e)
print("Original list")
[print('+'+str(e)) for e in x if e > 0]
[print(str(e)) for e in x if e < 0]
print("Positive integers")
[print('+'+str(e)) for e in lp]
print("Negative integers")
[print(e) for e in ln]
# Input
# int
# 0:
# 1
# int
# 1:
#
# int
# 1:
# wef
# int
# 1:
# wrfe
# int
# 1:
# wef
# int
# 1:
# 3
# int
# 2:
# 1
# int
# 3:
# -1
# int
# 4:
# 3
# Original
# list
# +1
# +3
# +1
# +3
# -1
# Positive
# integers
# +1
# +3
# +1
# +3
# Negative
# integers
# -1
# Additional Comments