Input Function And While Loop In Python
1. input() FUNCTION 101
# asking user input and storing it inside a variable
user_name = input("Please enter your name: ")
# printing the message using saved varibale value
print(f"Welcome to the website, {user_name.title()}")Please enter your name: Walter white
Welcome to the website, Walter White1.1. Prompt
a. Writing meaningful prompts
prompt = "What is your favorite car? "
fav_car = input(prompt)
print(f"User loves {fav_car.title()}")1.2. Using int() to Accept Numerical Input
1.3. The Modulo Operator
2. INTRODUCING while LOOPS
2.1. while Loop in Action
2.2. Letting User Choose When to Quit
2.3. Using a Flag
2.4. Using break to Exit a Loop
2.5. Using continue in a Loop
3. USING A while LOOP WITH LISTS AND DICTIONARIES
3.1. Moving Items from One List to Another
3.2. Removing All Instances of Specific Values from a List
3.3. Filling a Dictionary with User Input
Last updated