Skip to content
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?

You are viewing a single comment. View All
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