I Need Help...
print threeNum
b. check if index 0 is < 5
i. if threeNum[0] < 5, replace index 0 with the string: “small”
ii. else, replace index 0 with a string: “large”
c. print threeNum
i have to do this, but when i put the proper signs in, it throws a error at me. Any ideas for what i can do to fix it?
Coder100
You forgot that you are comparing to an integer!
Your list type is a string
You are comparing an int
so it will never be true!
Change your code to:
if threeNum[0] == "5": threeNum[0] = "small" print(threeNum) elif threeNum[0] == "5": threeNum[0] = "big" print(threeNum)
or:
if int(threeNum[0]) == 5: threeNum[0] = "small" print(threeNum) elif int(threeNum[0]) == 5: threeNum[0] = "big" print(threeNum)
Dominicl645
hey, thanks for the help.
@Coder100Dominicl645
how have you been during COVID?
@Coder100Coder100
good
@dominicl645Dominicl645
thats good.
@Coder100Coder100
thanks! You?
@dominicl645Dominicl645
im ok. thx for asking.
@Coder100Dominicl645
hey y'all, i need some help.
@Coder100
You need to do this:
You need to convert that first index of the list into a integer, since you have all strings in your list
If you have a list of strings, convert the indices to integers
or
make the list all integers
do
threeNum = [2, 7, 9] instead of threeNum = ["2", "7", "9"]
THANK YOU!!! THAT WORKED.
@SUHASTADIPARTH1:) hope you and everyone else is safe during COVID-19.
@SUHASTADIPARTH1tbh i hope COVID-19 ends soon. COVID is getting old, quick. if you or anyone on here got hit by Hurricane zeta, i hope yall are safe and sound.
@SUHASTADIPARTH1