-
Notifications
You must be signed in to change notification settings - Fork 266
Negative Numbers
Sar Champagne Bielert edited this page Apr 8, 2024
·
5 revisions
Unit 1 Session A (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Will the list only contain numbers?
- Yes.
- Is there always a negative number in the list?
- No. If there are no negative numbers, the function should not print anything.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create a function that prints all negative numbers in the list.
1) Loop through each number in the list
2) If the current number is less than zero, print it outdef print_negatives(lst):
for number in lst:
if number < 0:
print(number)
print_negatives([1,-2, 4, 3, -5])
# Output:
# -2
# -5
print_negatives([1,2,3,4,5])
# No output