Mar-12-2018, 11:06 PM
(This post was last modified: Mar-12-2018, 11:27 PM by the_communist_senate.)
Hi, I am new to the programing scene and I've come across a problem. I am working on a program that will take in five readings from the user. If the reading is between 80 and 100 the program should display "S", if it is between 30 and 80 it should display "M", and if it is between 0 and 30 it should display "P". I made the program using arrays just as my teacher instructed me to (this is an assignment for Computing Science. The program works fine if the number entered is 30 or below, however any higher and I get something on the lines of this
here is the code:
nevermind i just realised that i forgot that it was supposed to be elif.
this is the result of sleep deprivation
1 2 3 4 |
Traceback (most recent call last): File "C:\Users\Filip\Desktop\program design.py" , line 13 , in <module> if readingOne < = 30 and readingOne > = 0 : TypeError: '<=' not supported between instances of 'str' and 'int' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
readingPattern = [ "S" , "M" , "P" ] #Area 1 readingOne = int ( input ( "Please enter the first reading: " )) if readingOne < = 100 and readingOne > = 80 : readingOne = readingPattern [ 0 ] if readingOne < 80 and readingOne > 30 : readingOne = readingPattern [ 1 ] if readingOne < = 30 and readingOne > = 0 : readingOne = readingPattern [ 2 ] #Area 2 readingTwo = int ( input ( "Please enter the second reading: " )) if readingTwo < = 100 and readingTwo > = 80 : readingTwo = readingPattern [ 0 ] if readingTwo < 80 and readingTwo > 30 : readingTwo = readingPattern [ 1 ] if readingTwo < = 30 and readingTwo > = 0 : readingTwo = readingPattern [ 2 ] #Area 3 readingThree = int ( input ( "Please enter the third reading: " )) if readingThree < = 100 and readingThree > = 80 : readingThree = readingPattern [ 0 ] if readingThree < 80 and readingThree > 30 : readingThree = readingPattern [ 1 ] if readingThree < = 30 and readingThree > = 0 : readingThree = readingPattern [ 2 ] #Area 4 readingFour = int ( input ( "Please enter the fourth reading: " )) if readingFour < = 100 and readingFour > = 80 : readingFour = readingPattern [ 0 ] if readingFour < 80 and readingFour > 30 : readingFour = readingPattern [ 1 ] if readingFour < = 30 and readingFour > = 0 : readingFour = readingPattern [ 2 ] #Area 5 readingFive = int ( input ( "Please enter the fifth reading: " )) if readingFive < = 100 and readingFive > = 80 : readingFive = readingPattern [ 0 ] if readingFive < 80 and readingFive > 30 : readingFive = readingPattern [ 1 ] if readingFive < = 30 and readingFive > = 0 : readingFive = readingPattern [ 2 ] print (readingOne, readingTwo, readingThree, readingFour, readingFive) |
nevermind i just realised that i forgot that it was supposed to be elif.
this is the result of sleep deprivation