Why does my code not run when option2 is 1?
option2 = ""
specificReport = "yes"
if specificReport == "yes":
specificReport = str.lower(input("Do you want to look at the specific report (yes/no) : " ))
option2 = str.lower(input("Which data are you looking for \
(1. Location, 2. Type of Risk, 3. Risk Level , 4. Date & Time): "))
if option2 == 1:
locationValue = input('Enter the location you want to inspect: ')
LocationRow = (dataframe.loc[dataframe['Location Name'] == locationValue])
print(locationRow)
CodePudding user response:
Because the output of input
is a string, so you compare option2
(a string) with 1
(an integer). Either you convert the integer to string (i.e., '1'
instead of 1
) or you convert the output of input
to an integer (i.e., int(option2)
).
CodePudding user response:
Because it's a string. You need to make it an int
if int(option2) == 1
.
Also you don't really need str.lower() on the input - you can make in int() from there too.