How to Validate User Inputs in Python | Input Validation in Python

Поділитися
Вставка
  • Опубліковано 26 лип 2022
  • 💻 Get the Source Code and support the channel ❤️: www.buymeacoffee.com/fabiomus...
    ⬇️ LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW) 😉💪 ⬇️
    💻 My Source Codes: www.buymeacoffee.com/fabiomus...
    ☕ Buy me a coffee: www.buymeacoffee.com/fabiomus...
    😍 One-off donation: www.paypal.me/FabioMusanni/
    SKILLSHARE
    (Python, Web Dev, UI/UX Design, Music, Art, Animation and a lot more)
    🔗 skillshare.eqcm.net/5gxzD2 (Affiliate)
    DATACAMP
    (Python, ChatGPT, SQL, Power BI, and a lot more)
    🔗 datacamp.pxf.io/vN1bDj (Affiliate)
    COURSERA PYTHON
    (For beginners, Data Science, Data Analysis, AI, Cybersecurity and a lot more):
    🔗 imp.i384100.net/k0Nk60 (Affiliate)
    COURSERA WEB DEVELOPMENT
    (Full Stack, Front-End, Back-End, Web Design and a lot more):
    🔗 imp.i384100.net/EKWxBW (Affiliate)
    Learn how to validate inputs entered by the user like not allowing inputs that contain certain characters, allowing only numbers and a lot more.
    Complete list of what you'll learn:
    - Allow only numbers
    - Allow anything but numbers
    - Not allow inputs that contain certain invalid characters
    - Allow only certain values
    If the video was helpful, let me know in the comments down below and also like the video so that other people can see it. Needles to say I really appreciate your support 💪❤️
    📨 SUBSCRIBE so that you don't miss any new video:
    ua-cam.com/users/FabioMusann...
    🤗 BIO PAGE (contacts, etc): solo.to/fabiomusanni
    Create Your Bio Page (10% OFF Upgraded Plans 😉): solo.to/inv/NDE4NzE2
    🔗 RELATED CONTENT (videos, playlists, etc) 🔗
    Hangman Game Tutorial: • Python Hangman Game Tu...
    Python Playlist: • 🐍 Learn Python With Fa...
    🤩 AFFILIATE LINKS 🤩
    Create Your Bio Page (10% OFF Upgraded Plans): solo.to/inv/NDE4NzE2
    🧑🏻‍💻 ABOUT ME 🧑🏻‍💻
    I'm Fabio, I started programming with Python a lot of years ago and I fell in love with this world.
    I started this UA-cam channel to help you during your own journey and I hope that my help can make you an amazing programmer who loves this world as I do.
    Welcome on board!! 🚀
    #pythonWithFabioMusanni #python #pythonforbeginners #pythontutorial #pythonprogramming #coding #programming
  • Наука та технологія

КОМЕНТАРІ • 38

  • @FabioMusanni
    @FabioMusanni  2 роки тому +2

    💻 *Source Code:* www.buymeacoffee.com/fabiomusanni/e/185794
    ⬇️ *LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW)* 😉💪 ⬇️
    ☕ *Buy me a coffee:* www.buymeacoffee.com/fabiomusanni
    ❤️ *Support me monthly:* www.patreon.com/FabioMusanni
    😍 *One-off donation:* www.paypal.me/FabioMusanni/
    *SKILLSHARE*
    _(Python, Web Dev, UI/UX Design, Music, Art, Animation and a lot more)_
    🔗 skillshare.eqcm.net/5gxzD2 (Affiliate)
    *DATACAMP*
    _(Python, ChatGPT, SQL, Power BI, and a lot more)_
    🔗 datacamp.pxf.io/vN1bDj (Affiliate)
    *COURSERA PYTHON*
    _(For beginners, Data Science, Data Analysis, AI, Cybersecurity and a lot more):_
    🔗 imp.i384100.net/k0Nk60 (Affiliate)
    *COURSERA WEB DEVELOPMENT*
    _(Full Stack, Front-End, Back-End, Web Design and a lot more):_
    🔗 imp.i384100.net/EKWxBW (Affiliate)
    Thank you for the support!❤
    🎥All my videos about Python: ua-cam.com/play/PLs8qUrmRvaR0IT4IwJl-LSweAdACW-yLK.html

    • @gregoneill4391
      @gregoneill4391 Рік тому

      do you have a video on validaing forms with data? with pysimple gui for example I have tried a few way but it wont properly validate for me

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      @@gregoneill4391 Hello 😊 No, at the moment I don't have videos about PySimpleGUI.

  • @tronicit
    @tronicit 8 місяців тому +1

    I've been searching on how to select items from a list via input and the last part of your tutorial explained just that! Thanks very much 😁

    • @FabioMusanni
      @FabioMusanni  8 місяців тому

      Glad to hear that you found what you were looking for 😉💪 And thank you so much for the comment! 😍

  • @grecellmarciales3341
    @grecellmarciales3341 Рік тому +2

    Thank you for this, been running around in circles looking for the correct try..except.. for my float input for bmi calculation. Cant find clear explanation on the internet. This is veyr straightforward. Finally finished my assignment :)🤩☺☺ Subscribed🥰

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      Hello ☺️
      Well done!! 🤩 I'm very happy that you could finish your assignment thanks to my video! 😍 🥳 Thank you for the subscription and welcome! 🥰

  • @yashrajdeo1108
    @yashrajdeo1108 Рік тому +1

    Very useful. I could not find a good explanation about it anywhere.

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      Thank you for the comment! 🤗 I'm happy it was useful 💪😊

  • @ossy888888
    @ossy888888 Рік тому

    Saved me on my exam! Cheers!

    • @FabioMusanni
      @FabioMusanni  Рік тому

      Hey Oskar! Glad to hear that, keep it up! 💪🔥

  • @izharchishty9089
    @izharchishty9089 Місяць тому

    Thanks Brother Its Really Working

    • @FabioMusanni
      @FabioMusanni  Місяць тому

      Thank you for the comment! 💪😍

  • @python-cookie
    @python-cookie 2 місяці тому

    🚀 Your video was incredibly helpful, Fabio! As a beginner developer, learning how to validate user inputs in Python seemed daunting, but your clear explanations and practical examples made it so much easier to grasp. Now I feel more confident in handling user inputs and ensuring the integrity of my programs. Thank you for sharing your expertise and making coding more accessible for everyone! 💪❤

    • @FabioMusanni
      @FabioMusanni  2 місяці тому +1

      Thank you so so much for your kind words! Really appreciated! ❤😊💪

  • @JoeDonRB
    @JoeDonRB Рік тому +1

    Fabio, can you Store strings ‘stone’, ‘paper’, ‘scissors’ in a list
    Ask the user to input their choice (validate)
    Pick a random item from the list to represent the computer
    Use if, elif commands to check who wins
    Display who won on the screen.

    • @FabioMusanni
      @FabioMusanni  Рік тому

      Hello 😊
      Yes, you can use one of the methods I explain in the video for the validation, so that the user can only enter one of the 3 values and then you can pick a random item using the built-in random module, have a look at that. 😉🤗

  • @tazkiatahmid9754
    @tazkiatahmid9754 Рік тому

    Why a question arrives when i do input?

  • @gamerbase5188
    @gamerbase5188 2 місяці тому

    and what if i want a certain word ? how can i make it so everything but this word gets marked as Invalid?

    • @FabioMusanni
      @FabioMusanni  2 місяці тому

      You can make a list of valid words, and check if the word entered is in that list, if so you go ahead, if not you ask for another word.

  • @Meyaal
    @Meyaal Рік тому +1

    Hello Fabio! This is amazing tutorial for my understandig! I really enjoed it😀 I am new at coding, how can I implement that on the hangman game the one that you created in the other video. I need to make the code to handle empty and invalid inputs from users without losing lifes if you understand what I mean. I need that specific for the hangman game that you have created because I don’t know how to implement that by my own. Plaese help me 🙏🏼

    • @FabioMusanni
      @FabioMusanni  Рік тому +2

      Hello Meya, thanks for the comment! 😊 Glad you enjoyed it, I hope you are learning a lot with my videos.
      In the Hangman game video at the line 33 and line 38 you get the "letter_user". Instead of just writing that, you need to write what I teach you in this video from min 11:25.
      You literally just have to write the "tuple_valid_chars" (13:31) at the beginning of the program where you have the list of all the variables (e.g. line 22), then you need to replace the code on line 33 and 38 with the code from line 60 through 68 in this video (13:44). Of course "user_input" should be named "letter_user" and make sure you keep the right indentation.
      I'm aware that you'll be writing the same lines of code twice, but to avoid that we would need to change the code a little bit and I can't go over it here.
      I hope this helps, you should have all the information you need to make it work, remember that it's really important to try, fail, try again, etc, especially at the beginning, it's how you get better. 💪
      Of course keep watching my videos and experiment with what I teach you as well 😉
      Bye 😊

    • @Meyaal
      @Meyaal Рік тому

      @@FabioMusanni thanks a lot for your answer😀 I’ll try and do my best. Promise to watch all your videos and keep ask questions 😉 you are wonderfull person and I wish you all the best in your career path!

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      Thank you very much for your kind words! ☺️ I love it when people ask questions, because it means they really want to learn and are watching my videos seriously. So your questions/comments will always be appreciated. Bye ☺️🤓

    • @Meyaal
      @Meyaal Рік тому +1

      @@FabioMusanni well I have a question about long line, I get too long line error for the tuple_valid_char, I tried to use backslash to break the line but i doesn’t work for me. Do you have other advice how I can do? 😃

    • @FabioMusanni
      @FabioMusanni  Рік тому

      That's really strange. Do you get that error when running the code in the terminal or is it an error that the code editor gives you? Which editor are you using?

  • @quiztherapy6851
    @quiztherapy6851 Рік тому

    when i entered break it throws an error that break can be used only within a loop. I checked everything seems ok. How to fix it?

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      Hello 😊
      That error is definitely caused by a wrong indentation. The "break" needs to be under the while loop but also indented at least once. So you don't want something like this:
      while True:
      break
      But something like:
      while True:
      break

  • @jayl9744
    @jayl9744 Рік тому

    I trying to add to this to a calculator i am making in python. But i having difficulty applying it to the (num 1 and num 2 user input portion if the user does enter a integer. it just returns an error, its not attached to the user input portion. How do i error check num 1 and num 2 for non interger values. i did use try and error but just had indentation issues. Thanks

    • @FabioMusanni
      @FabioMusanni  Рік тому +1

      Hello Jay. Thanks for the comment. 😊
      The first example in the video does exactly what you are asking. You need to use the try except block with a while True loop if you want to keep asking the user until they enter two valid numbers.
      So, just write your two inputs (the one for num1 and the one for num2) in place of the "user_input" in the video and then try to convert both of them in the try block. If both of them are valid, then the program will continue and you can use those numbers below the try/except block, however, if at least one number is not valid, the program won't continue and the code in the except block will be run, so in the except block you can write what you want python to do if the user enters something wrong (in the video I just let them know with a message) 😊
      Of course keep all the indentations in place, they are extremely important, and do things at steps, so don't write all of your code at once, just try this validation and if that works, then add your code so that you know if the problem is the validation or something else.
      I hope this helps 💪😉

    • @jayl9744
      @jayl9744 Рік тому

      @@FabioMusanni Thank you that helped alot!! Writing a calculator program but trying to make it more functional with more variables the user can calculate. So i need a lot of ways to make sure the user can enter the right input and then end the program at anytime while its running.

    • @FabioMusanni
      @FabioMusanni  Рік тому

      No worries! 😉 Keep up the good work! 💪🔥

  • @ayushvispute4416
    @ayushvispute4416 9 місяців тому

    I ain't getting ValueError as a seperate feature