-1
n = int(input("Enter N number : "))
a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n]
print("\nList is : ", a)
list1=a
list1.sort()
print("Smallest element is:", min(list1))
print("Largest element is:", list1[-1])
def Average(list1):
    return sum(list1) / len(list1)
list1=a
average = Average(list1)
print("Average of the list =", round(average, 2))
element=int(input("Enter a number to count how many times is repeated: "))
list1.count(element)
print("\nNumber is repeated" ,element , "times")

how can i fix this logical error ?enter image description here

my results show this: Enter N number : 5

Enter the numbers : 1 2 3 4 5

List is : [1, 2, 3, 4, 5] Smallest element is: 1 Largest element is: 5 Average of the list = 3.0 enter code hereEnter a number to count how many times is repeated: 3

Number is repeated 3 times

  • 1
    Do `repeats = list1.count(element)` and put `repeats` in your `print()` call instead of `element`. – BoarGules Jul 09 '21 at 09:49
  • got it!! print("\nNumber is repeated" ,list1.count(element) , "times") – Maysam Alkhalaf Jul 09 '21 at 09:53
  • 1
    this workss perfect! ==> print("\nNumber is repeated" ,list1.count(element) , "times") – Maysam Alkhalaf Jul 09 '21 at 09:53
  • how can i do that in my code?? Insert the new value 130 in the index 3 without deleting the old value at that index – Maysam Alkhalaf Jul 09 '21 at 09:58
  • And wy do you do `list1=a`? If you want the list to be known as `list1` then create it with this name. If you thought you get a copy of list `a` with that: you don't. You still have one list, but you can access it under 2 different names. – Matthias Jul 09 '21 at 11:10

1 Answers1

2

You don't use list1.count(element) statement at all. You count the number of elements in the list, but you never pass it into print statement. Instead, you pass element which is the input provided.

list1.count(element)
print("\nNumber is repeated" ,list1.count(element) , "times")