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
  • Find an example of Python program on the Web and provide a link for the source....

    Find an example of Python program on the Web and provide a link for the source. Discuss what the program does and whether it has inputs, processes, and outputs.

  • 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?

  • Search the Web for an example of list in Python code, share it, and post the...

    Search the Web for an example of list in Python code, share it, and post the link for the site. Describe how it works in English as an algorithm, which is a sequence of simple steps. Why do we use lists in Python? How do they differ from a dictionary?

  • 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...

  • Overview Module 3 Assignment 2 features designing a program using pseudocode and then completing the program...

    Overview Module 3 Assignment 2 features designing a program using pseudocode and then completing the program in Python using strings. M3Lab2 asks you to write a Mortgage Loan Calculator. 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 Pseudocode and Python Program with Strings M3Lab2.txt has some of the...

  • Python programming question Using an adjacency matrix: Take a txt file and have the program read...

    Python programming question Using an adjacency matrix: Take a txt file and have the program read it and output the contents into an adjacency matrix. - The txt file would have the size of the matrix and a list of names. - Print the filled matrix of the names - After each iteration, the program will ask, 'continue'? - Show how to swap names for the next iteration(Program would take an input of two names and swap them) Example: input:...

  • Hello! I'm looking for help with this assignment. Complete a program in pseudocode and Python that...

    Hello! I'm looking for help with this assignment. Complete a program in pseudocode and Python that performs the following tasks. Open the file called M4Lab1ii.py linked below these instructions in your M4 Content module in IDLE. Save as M4Lab1ii.py. Replace ii with your initials. [example for someone with the initials cc: M4Lab1cc.py] Complete Steps 1-7 as requested within the code’s comments. Run your program and test all four calculations, then exit the program. Save your program as M4Lab1ii.py using your...

  • 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...

  • 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...

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