Python Tutorial for Beginners - While Loop with User Input - What is the result of -1 + 1?

 ðŸ‘Ļ‍ðŸŦ 4K | Microsoft Visual Studio 2022 - Python Tutorial - Python for Beginners - While Loop with User Input | What is the result of -1 + 1?



In this video tutorial you will learn:

- Python if else statement

- Get user input to stop a while loop

- While loop to check for valid user input

- Asking the user for input until they give a valid response

- How would I use a while loop to keep requesting user input

- Exception and Error Handling in Python

- Python Exception Handling Using try and except statement



Python Source Code by iBasskung.


# Python Comment: Loop until a specific user input Demo by iBasskung.


# Python while loop

while True:

    fullname = input("Please enter your full name: ")

    # Check empty string.

    if (fullname and not fullname.isspace()):

        # Remove spaces at the beginning and at the end of the string.

        # using the strip() method.

        print("\nHello, " + fullname.strip() + "!\n") # \n = new line.

        # Terminates the current loop.

        break

    else:

        print("\nThe string is empty.\n")

        # Continues to the next iteration.

        continue


answer = -1 + 1


while True:

    # Python Exception Handling.

    try:

        # Convert user input to a number using int() function.

        result = int(input("What is the result of -1 + 1? "))

        if(result == answer):

            break

        else:

            print("\nYour answer is incorrect. Try again...\n")

            continue


    except ValueError:

        print("\nPlease input integer only...\n")

        continue


print("\nYour answer is " + str(result) + "." + " That's correct!\n")


print("Thanks so much for watching. Pleae like my video ^_^\n")


#END


ðŸ“ē Join this channel to get access to exclusive perks!

🎁 Online Programming Courses: https://bit.ly/38XHp11


ðŸŽŊ See more:
ðŸ“ē YouTube: https://www.youtube.com/c/iBasskung
ðŸ“ē Facebook: https://www.facebook.com/CodeAMinute
ðŸ“ē Udemy: https://www.udemy.com/user/tanin-sangngam
ðŸ“ē SkillLane: https://www.skilllane.com/instructors/iBasskung


ðŸ’Ŋ THANK YOU SO MUCH ðŸ’Ŋ


#Python #WhileLoopUserInput #VisualStudio2022 #iBasskung #ComputerProgramming

Comments