Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

While working on a Python Project, I was tasked to complete a While Loop, I completed the Loop, and I wanted the program to check

While working on a Python Project, I was tasked to complete a While Loop, I completed the Loop, and I wanted the program to check data to see if I enter a positive integer. Then loop if i put in a negative or letter character to ask the user to put in a positive integer until the user does so. The file needs to write to a file at the end with the results. I ran the program and no matter what number I put in, it still displays that I have put in a negative number and stay on loop. I need help. image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

File Edit Format Run Options Window Help | # PROGRAMMER: # PROGRAM NAME: WHILE LOOP BUDGET ANALYSIS # DATE WRITTEN: 2/21/20 VIT PURPOSE: USE WHILE LOOP TO DETERMINE IF BUDGET ITEMS ARE "); outFile = open(outFileName, "w"); #== # Define the ending / target value # Check the data type for number of budgetItems [ in this case "howMany" is the variable to check while True: try: print("How many total budget items do you have? [Enter Positive Number]"); howMany = int(input()); except ValueError: print("The information you entered is not correct data type - please enter a value > 0"); continue; else: # check to see if the value is a positive whole number if howMany 0 "); continue; break; print("=" * 80); Ln: 2 Col: 17 File Edit Format Run Options Window Help # Check to see if the target or ending value is a positive value; Flowgorithm automatically checks the data type while howMany = 0: print(" (Re-Enter] How many budget itens do you have? [positive whole value only "); howMany = int(input()) # update wrongData lcv wrongData = wrongData + 1 # WHILE LOOP TO TOTAL THE AMOUNT OF THE BUDGET # tests the lcv days against the target value howMany while items 0"); continue; else: if (budgetAmount 0 "); continue; break; # end checking the data type and for positive values outFile.write("Enter the number of items for budgetAmount # " + format(items, "20") + ": "); outFile.write(format(items, ",") + ": "); # WHILE LOOP TO CHECK DATA TYPE and ensure POSITIVE VALUES ARE ENTERED. while items Type your first name and last name here: "); outFile.write("= * 80 + " "); outfile.close(); # closes the newly created external output file # END PROGRAM Ln: 2 Col: 17 l ytron 3.6.1 Sheila File Ball Dubug Options Window Help Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) (MSC v. 1916 32 bit (Intel) Type "help", "copyright", "eredits" or "license()" for more information. on win32 - RESTART: C:\Users\Italy\Desktop\Python Test BUDGET_ANALYSIS_WHILE LOOP CHECK DATA.PY Enter the Tile Name of the file where you want to write the output - end the file with .txt -->Test.txt How many total budget Items do you have? [Enter Positive Number) Enter the number of items for budgetAmount # 1 You entered a negative number - please re-enter positive value > 0 Enter the number of items for budgetAmount # 1 You entered a negative number - please re-enter positive value > 0 Enter the number of items for budgetAmount # 2 You entered a negative number - please re-enter positive value > 0 Enter the number of items for budgetAmount # 6 -5 You entered a negative number - please re-enter positive value > o Enter the number of items for budgetAmount # -5 EN CARD

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions