5 Comments
User's avatar
VINOD VIJAYAN's avatar

I wrote like this:

def count_occurrences():

lst = input("Enter a list of numbers separated by commas: ").split(",")

lst = [int(num) for num in lst]

target = input("Enter the number you want to count: ")

count = lst.count(target)

print(f"The number {target} appears {count} times in the list.")

count_occurrences()

Expand full comment
Bijal's avatar

I noticed that the count() function can take a string as input. So, I'm just curious—why would we need to convert the input to an integer when counting occurrences? Is there a specific case where this is necessary?

I have used like this

user_list = input("Enter a list of numbers seprated by commas")

for num in user_list:

number_list = user_list.split(",")

number_list.append(num)

user_input = input("Enter the number you want to count: ")

number_appered = number_list.count(user_input)

print(f"The number {user_input} appears {number_appered} times in the list")

Please let me know

Thanks

Expand full comment
Anekali's avatar
2dEdited

Looking for a way to automatically show a number (from a database list)that was listed the “most” when a button is clicked and the same with a number listed the least (from a list in a database) when a button is clicked.

Using VS CODE with python.

For example: I have an excel database with 20 numbers with some numbers repeating.

When I click a button named MOST, on my app, it will automatically show the number listed/appearing the MOST from the excel database.

Can you please help with this? I’m new to Python & va Code.

Email: anekali5688@gmail.com

Expand full comment
Ardit Sulce's avatar

You need to pick a GUI library first. If you want a desktop app, pick something like Tkinter. If you want a web app, pick Streamlit. There are projects on Tkinter and Streamlit here on Daily Python Projects. I hope this helps.

Expand full comment
Greg's avatar

Code from my phone:

import os

iswin = os.name.upper() == "NT"

def cls(): os.system("cls" if iswin else "clear")

numlist = []

def shownums():

print("Numbers:", ", ".join(map(str, numlist)))

if __name__ == "__main__":

while True:

cls()

shownums()

try:

msg = (

"enter some numbers individually."

"\npress enter after every number."

"\nleave blank when done. >"

)

numlist.append(int(input(msg)))

except: break

cls()

shownums()

searchcount = int(input("What number are we counting? >"))

cls()

print(

f"There are {numlist. count(searchcount)} instances of '{searchcount}' in the list."

)

shownums()

Expand full comment