Python Forum
How to make the function to prompt the user repeatedly till he enters a no
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make the function to prompt the user repeatedly till he enters a no
#1
def ck_no(prompt):
    while True:
        try:
            
            lst = (2,3,4)
            if prompt not in lst:
                print("not in list")
                raise ValueError
            else:
                print("In the List")
        except ValueError as e:
            print(e)
            return
            
ck_no(int(input(print("Enter a No: "))))
Output:
Enter a No: None
After calling the function it prompts the user to enter the no. But it prints none. Beside none if enter the no it accepts and the pgm continues. How to correct this none.

I want to prompt the user again and again to enter different nos. How to do this?

Thanks
Reply


Messages In This Thread
How to make the function to prompt the user repeatedly till he enters a no - by sbabu - Feb-15-2020, 04:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a menu and execute a function based on user selection in python? Thedarkphoenix 1 1,345 Nov-23-2022, 07:53 PM
Last Post: Larz60+
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,833 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,529 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Imported function causes prompt repetition ward 3 2,591 Feb-06-2019, 02:16 AM
Last Post: perfringo
  Writing incorrect passwords to a file till its correct garth 2 4,971 Feb-10-2017, 11:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020