ðĻðŦ 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
Post a Comment