Apr-17-2017, 10:42 PM
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!