Skip to content
← Back to Community
I Need Help...
Profile icon
Dominicl645

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?

Answered by SUHASTADIPARTH1 [earned 5 cycles]
View Answer
Voters
Profile icon
HunterHolcomb90
Profile icon
SavageSpray
Profile icon
AnimeLover1069
Profile icon
cookieartist350
Profile icon
Dominicl645
Comments
hotnewtop
Profile icon
SUHASTADIPARTH1

You need to do this:

threeNum = ["2", "7", "9"] if int(threeNum[0]) > 5: threeNum[0] = 'small' else: threeNum[0] = 'large' print(threeNum)

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"]

Profile icon
Dominicl645

THANK YOU!!! THAT WORKED.

@SUHASTADIPARTH1

Profile icon
SUHASTADIPARTH1
Profile icon
Dominicl645

:) hope you and everyone else is safe during COVID-19.

@SUHASTADIPARTH1

Profile icon
SUHASTADIPARTH1
Profile icon
Dominicl645

tbh 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

Profile icon
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)
Profile icon
Dominicl645

hey, thanks for the help.

@Coder100

Profile icon
Coder100
Profile icon
Dominicl645

how have you been during COVID?

@Coder100

Profile icon
Coder100
Profile icon
Dominicl645

thats good.

@Coder100

Profile icon
Coder100

thanks! You?

@dominicl645

Profile icon
Dominicl645

im ok. thx for asking.

@Coder100

Profile icon
Dominicl645

hey y'all, i need some help.

@Coder100