Home > database >  Please help me with the input and how's the output works
Please help me with the input and how's the output works

Time:11-19

def down_detector(nums) {
  nums = int(input('Enter nums: '))
  for i in range(len(nums) - 1):
    if nums[i]==5 and nums[i 1]==9:
      return 1
    if nums[i]==5:
        return 1
    if nums[i]==5 and nums[i]==11:
        return 2
    print(nums)

CodePudding user response:

I'm not quite sure what your trying to do, but this is my best guess:

The main problem with your code is you are inputting nums as an int, when it really is a list. To solve this problem, we can use .split() like this:

nums = input('enter numbers divided by spaces').split()

However, please do note that all the values of this list will be strings, not integers, so we do:

nums = [int(i) for i in nums]

Afterwards, your if statements should work, but as Pixelbog pointed out, your code is a bit convoluted, so you might want to fix that as well!

CodePudding user response:

I can't really help you with your code, because it doesn't make any sense. But I can try my best explaining you were the problems are :)

  1. Line1: In Python we don't use "{". We use ":" instead
  2. Line2: This code can stand inside your function, but then remove the "nums" parameter in Line1 or move it outside of the function
  3. Line4: This line doesn't make any sense to check if nums[i 1]==9 because you check it in Line6 for 5 anyways so no matter if it is 9 or not, you will always get returned 1
  • Related