About 18,500,000 results
Open links in new tab
  1. python - How do I do to ask something in if/else structure?

    Dec 20, 2020 · I started with basic if/else structure but I am blocked because I don't know how to ask something in an if/else structure. For example : A = input("Question 1 ? ") if A == "yes": print("Consequence of yes to question 1") else: A == "no" print("Consequence of no to question 1") if A == "no": B = input("Question 2 ?")

  2. How to make python code go back to the original question after it hits ...

    Aug 25, 2020 · answered=False while(not answered): which_bedroom = input('....') #insert your long string if which_bedroom=='1': print('wrong answer try again') elif which_bedroom =='2': print('wrong answer try again') elif which_bedroom == '3': answered=True print('correct! next question...') else: print('Invalid input try again') next_question() #copy above ...

  3. Asking the user for input until they give a valid response

    Apr 25, 2014 · How do I ask for valid input instead of crashing or accepting invalid values (e.g. -1)? The simplest way to accomplish this is to put the input method in a while loop. Use continue when you get bad input, and break out of the loop when you're satisfied. Use try and except to detect when the user enters data that can't be parsed. try:

  4. Yes/No question with user input in Python - bobbyhadz

    Apr 9, 2024 · To ask the user a yes/no question: Use the input() function to take input from the user. Perform an action if either condition is met. We used the input() function to take input from the user. The if statement checks if the user entered yes and prints a message.

  5. 10 if-else Practice Problems in Python - LearnPython.com

    May 18, 2024 · These ten if-else Python practice problems provide you some hands-on experience. And don’t worry – we’ve provided full code solutions and detailed explanations! Python is particularly good for beginners to learn. Its clear syntax can be read almost as clearly as a normal sentence.

  6. Python Conditional Statements and Loops

    Exit an If Statement in Python; The if-elif-else Statement. ... Loops allow you to execute a block of code multiple times. Python provides two main types of loops: for loops and while loops. For Loops. The for loop in Python is designed to iterate over a sequence (like a list, ...

  7. Python if, if...else Statement (With Examples) - Programiz

    In this case, Python thinks our if statement is empty, which results in an error. An if statement can have an optional else clause. The else statement executes if the condition in the if statement evaluates to False. Syntax. # body of if statement else:

  8. Python If Else Statements – Conditional Statements - GeeksforGeeks

    Mar 8, 2025 · In Python, If-Else is a fundamental conditional statement used for decision-making in programming. If…Else statement allows to execution of specific blocks of code depending on the condition is True or False. if statement is the most simple decision-making statement.

  9. Python - if , if..else, Nested if, if-elif statements - GeeksforGeeks

    Mar 7, 2025 · Below is the flowchart by which we can understand how to use if-else statement in Python: In this example, the code assigns the value 3 to variable x and uses an if..else statement to check if x is equal to 4. If true, it prints “Yes”; otherwise, it prints “No,” demonstrating a conditional branching structure.

  10. How to Use Conditional Statements in Python - Expertbeacon

    Aug 28, 2024 · With the humble if-else statement, you can write Python code that adapts to different inputs and situations. After 15+ years of Python development, conditionals remain one of the first concepts I teach new programmers. In this comprehensive guide, you‘ll gain a masterful understanding of conditional logic in Python.

  11. Some results have been removed