Question

Find an example of a Python program on the Web that illustrates the program’s decisions using...

Find an example of a Python program on the Web that illustrates the program’s decisions using if and while statements. Provide a link for the source.


What is happening in your programming example? Describe it in English as an algorithm.


After the else statement executes, which program statement executes next in your example?


0 0
Add a comment Improve this question Transcribed image text
Answer #1
""" A simple program to demonstrate WHILE LOOP, IF ELSE condition """ # initialize n = 5 n = 5 # if we don't know how many times loop runs then use while loop # WHILE LOOP checks whether n > 0 # if yes then it decrements n by 1 and prints n # After it uses a if statement to check whether n == 2 # if yes then it breaks the WHILE LOOP # else It print "Loop done" after printing each value of n while n > 0: n -= 1 print(n) if n == 2: break else: print("Loop done.") 

LINK SOURCE

https://realpython.com/python-while-loop/

STEPS

1) Asign n = 5

2) The program uses a WHILE LOOP to check whether n > 0.

3) If n > 0 it decrements n by 1 and prints n

4)After that it uses a if statement to check whether n is equal to 2

5)If n == 2 is True then it breaks the while loop else it prints "Loop done" after each value of n

After the ELSE statement it again starts the condition in WHILE  LOOP

Add a comment
Know the answer?
Add Answer to:
Find an example of a Python program on the Web that illustrates the program’s decisions using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Search the Web for an example of a structured program in Python. Share the link to...

    Search the Web for an example of a structured program in Python. Share the link to the example and describe how it works. Why do we use structured programming in Python?

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is  1, 5, -3, 4,...

  • Create a python program to play rock paper scissors using a while loop and if statements....

    Create a python program to play rock paper scissors using a while loop and if statements. I have started but have gotten stuck in a continuous loop. Please look over my code and help me find where I went wrong. Here it is: import random #Choice weapons=['Rock' ,'Paper' ,'Scissors'] print('Rock, Paper, Scissors!') print('Rock, Paper, Scissors!') print('Shoot!') human=input('Choose Rock, Paper, Scissors, or Quit! ') print('')#Blank Line while human != 'Quit': human_choice=human computer=random.choice(weapons) print(computer) if human==computer: print("It's a tie!") elif human=='Rock': if...

  • PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study...

    PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study / engineering / computer science / questions and answers / python programming - code the program based on ... Your question has been answered! Rate it below. Let us know if you got a helpful answer. Question: PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE... Bookmark PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED Rainfall Algorithm Declare and...

  • As we continue with our study of programming fundamentals, here is a short extra credit programming...

    As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the...

  • 1. program to use with number 1. 2. Comparing Python and Java Discussion Forum 14 days ago Use the Python...

    1. program to use with number 1. 2. Comparing Python and Java Discussion Forum 14 days ago Use the Python IDLE editor to create the source code for the "numberguess.py" pro- gram. This program is in the "Basic Python Pro- gramming" chapter in its "An Example Python Program: Guessing a Number" section. If you mistakenly create syntax errors, find and fix them. Run the program and test it with various values. Refer to the "numberguess.py Program document to see example...

  • Using python, write code for problem. Please also put screenshot of your code. The following program...

    Using python, write code for problem. Please also put screenshot of your code. The following program will perform properly if the user enters 0 in response to the request for input. However, the program will crash if the user responds with "eight". Rewrite the program using a try/except statement so that it will handle both types of responses. See Fig. 6.1. while True: n = int (input ("Enter a nonzero integer: ")) if n! = 0: reciprocal = 1/n print...

  • * This program illustrates how to use a sequential search to find the position of the...

    * This program illustrates how to use a sequential search to find the position of the first apparance of a number in an array TODO#6: change the name to your name and date to the current date * * Created by John Doe, April 17 2019 */ #include using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() { //TODO#1: declare an integer array named intList with size of...

  • Write a software key-logger and test it while you fill out a web form or type...

    Write a software key-logger and test it while you fill out a web form or type in the contents of a document using your favorite document preparation software. You can use Java or Python to do this assignment. C and C related programming language is not allowed for this assignment. Hints: You can find a demo and API for key-logger hook in the following link for JAVA. https://github.com/kwhat/jnativehook This project can only be used to learn how to use JNI...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT