(I am new to Python so forgive me in advance) I have to write a program that calculates the total of integers from 1 to the user input. So if I input 4, it would add 1+2+3+4. I also added an argument that makes a number that is less than 1 print "invalid number". I am stuck on adding a sentinel that is a letter. Thank you
value = input("Enter a number or press J to terminate: ")
if value < 1:
print("Invalid number")
else:
i = 1
while value > 1:
i = i + value
value = value - 1
print(i)
This is the code that I tried to do:
value = input("Enter a number or J to finish: ")
if value < 1:
print("Invalid number")
while value ! = "J":
i = float(value)
else:
i = 1
while value > 1:
i = i + value
value = value - 1
print(i)
value = input("Enter a number or J to finish: ")
Error when J or any number is inputted, '<' not supported between instances of 'str' and 'int'.