7. Input & While Loops
1. Simple Definition & Meaning
User Input lets the program ask the user a question and wait for an answer. A While Loop keeps doing something over and over again AS LONG AS a condition is true.
2. Real-World Examples
- Example (Input): When a video game asks "What is your name?" and you type it in.
- Example (While Loop): WHILE you are hungry, keep eating chips. When you are not hungry anymore, stop!
3. Important Points
- Use
input("Prompt text")to ask the user something. - Use a
whileloop to repeat actions. Example:while score < 10: - Be careful not to create an infinite loop (a loop that never stops)!
📝 Exam Notes (Quick Revision)
- input(): Pauses the program and waits for user text. Always returns a string!
- int(): Use to convert input strings to numbers.
- break & continue:
breakexits the loop immediately,continueskips to the next turn of the loop.