I need help, I have to create a program that uses a list display to create a list containing the integers from 1 to 10 in increasing order, and output the list. Then ask the user to enter a number between 1 and 10, replace this number with the missing str object, and output the list. If the user enters a string that does not represent an integer between 1 and 10, it instead generates the appropriate message indicating this situation, as shown in the sample runs:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter an integer between 1 and 10 >5
[1, 2, 3, 4, 'gone', 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter an integer between 1 and 10 >15
15 is not between 1 and 10
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Enter an integer between 1 and 10 >hello
hello is not a positive integer
I have created the following code:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(my_list)
a = input('Enter an integer between 1 and 10 >')
b = (a.isalpha())
if int(a)<10 and b == False:
c = my_list.index(int(a))
d = my_list.remove(int(a))
e = my_list.insert(c, 'gone')
print(my_list)
elif int(a) and b == False:
b == True
print (a, 'is not between 1 and 10')
else:
print(str(a), 'is not a positive integer')
but i got the following error:
RuntimeErrorElement(RuntimeError,Error on line 6:
c = my_list.index(int(a))
ValueError: 0 is not in list
)
Does anyone know how I could solve this problem?