Python Forum
instruction refused on a "while loop"
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
instruction refused on a "while loop"
#11
1. assign user input to variable (str)
2. check the user input. if it is THAT specific value you want to use for quit - then use break to exit the loop
3. if it is not p.2 - convert to number and calculate
4. Also why you set size = 40 and never use it. think what condition should you use in the while statement.
Reply
#12
Here is the solution of my problem using error handling. I hope the code will be tagged. Here is the code:::::::::::::::::::::::::::
file5.py
size = 40
print("here is the addition of many numbers (even with a .) Maximum of numbers=", size)
print("Once you have finished your list of numbers, just press $ to indicate the end\n")
total = 0.0
value = 0.0
count = 1
while (count != 0):
    try:
        value = float(input("enter the value: "))
    except ValueError:
            count=count-1
            average = total/count
            print("average value= ", average)
            exit()
    else:
        print(value)
        print(total)
        total = value + total
        print(total)
        count = count + 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Illegal instruction (core dumped) when import pandas. amandacstr 1 2,086 Dec-31-2022, 11:31 PM
Last Post: stevendaprano
  Illegal instruction? working code for months? korenron 4 13,045 Aug-05-2021, 09:57 AM
Last Post: korenron
  Docker-compose on Pycharm - Connection refused rstambach 3 3,379 Apr-08-2021, 03:07 AM
Last Post: rstambach
  permutations calculation with a while instruction kwak86 2 2,266 Sep-10-2018, 02:09 PM
Last Post: kwak86
  Nginx Uwsgi Django 111 Connection refused while connecting to upstream sandyman 0 5,101 Sep-18-2017, 07:05 AM
Last Post: sandyman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020