Python Forum
Error in loops, new to Python
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in loops, new to Python
#1

I just recently got involved with trying to learn python and am actually trying to teach myself to help me get a better job in the GIS field. Have tried many ways to get the right code for these two problems. I'll post the questions along with my code. I'm thinking it is a syntax issue in 1 or 2 of my lines. Thanks for the help and please remember I am just a beginner!
Question1:
  • On the line labeled Input write the following numbers: 4 6 12 9 1 2
  • Draw a box, label the box S, write the number 0 in box S
  • Draw a box, label the box C, write the number 0 in box C
  • Draw a box, label the box X write the number 999 in box X
  • If there are still numbers on the line labeled Input then do the next instruction, otherwise do instruction 10
  • Replace the number in box X with the the next number on the line labeled Input, erase from the Input line the number that was copied to box X
  • Replace the number in box S with the sum of the number that is currently in box S plus the number in box X
  • Replace the number in box C with the number that is one more than the number currently in box C
  • If the number in box C is greater than 0 then do the next instruction, otherwise do instruction 14
  • Draw a box, label the box A, write the value in box S divided by the value in box C in box A
  • Write the number in box A on the line labeled Output Go to instruction 15 Write the words "No answer" on the Output line

list = [4,6,12,9,1,2]
S = 0
C = 0
X = 999
while list[0]:
    S = S + X
    C = C + 1
if C > 0:
    A = S/C
    print(A)
else:
    print("No Answer")

Thinking I may have a syntax issue or error in my loop
Question 2:
  • Put the following numbers in boxes 0 - 5, one number per box: 3, 17, 4, 19, 8, 2
  • Draw a box, label the box I, write the number 0 in box I
  • Draw a box, label the box X, write the number 0 in box X
  • Draw a box, label the box G, copy the number from numbered box 0 to box G
  • If the number in box I is less than 6 then do the next instruction, otherwise do instruction 10
  • If the number in the numbered box whose number is the same as the number in box I is greater than the number in box G then do the next instruction, otherwise do instruction 8
  • Replace the number in box G with the value currently in the numbered box whose number is the same as the number in box I
  • Replace the number in box X with the number that is in box I
  • Replace the number in box I with the number that is one more than the number currently in box I
  • Go back and do instruction 4 again Write the number in box G on the line labeled Output Write the number in box X on the line labeled Output
list = [3,17,4,19,8,2]
I = 0
X = 0
G = list()
while I < 6:
    list(I) > G
    G = list(I)
    X = I
    I = I + 1
    print(G)
    print(X)

this one threw me for a spin
Appreciate any help!
Reply


Messages In This Thread
Error in loops, new to Python - by jhall710 - Apr-17-2017, 10:42 PM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 02:18 AM
RE: Error in loops, new to Python - by jhall710 - Apr-18-2017, 02:27 AM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 02:28 AM
RE: Error in loops, new to Python - by jhall710 - Apr-18-2017, 02:35 AM
RE: Error in loops, new to Python - by nilamo - Apr-18-2017, 03:29 AM
RE: Error in loops, new to Python - by sparkz_alot - Apr-18-2017, 12:50 PM
RE: Error in loops, new to Python - by smbx33 - Apr-23-2017, 10:19 AM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 03:43 AM
RE: Error in loops, new to Python - by smbx33 - Apr-24-2017, 04:32 AM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 06:41 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 04:05 PM
RE: Error in loops, new to Python - by wavic - Apr-24-2017, 06:47 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 06:47 PM
RE: Error in loops, new to Python - by wavic - Apr-24-2017, 06:53 PM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 07:02 PM
RE: Error in loops, new to Python - by zivoni - Apr-24-2017, 07:50 PM
RE: Error in loops, new to Python - by volcano63 - Apr-24-2017, 08:16 PM
RE: Error in loops, new to Python - by smbx33 - Apr-24-2017, 08:49 PM
RE: Error in loops, new to Python - by nilamo - Apr-24-2017, 09:44 PM
RE: Error in loops, new to Python - by smbx33 - Apr-25-2017, 05:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to python! Loops Seeley307 3 77,485 May-15-2020, 02:27 PM
Last Post: ibreeden
  Python for loops giving error Petrus 12 5,778 Jan-09-2019, 08:02 AM
Last Post: Petrus

Forum Jump:

User Panel Messages

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