I have code here and when I input a word such as dog the code stops working. I need the code to ask words as well as numbers as it is part as an assignment I am doing
The code should look like this when outputted
Enter 1 for a loop, 2 for a while loop:1
How many strings do you want to enter?:3
Enter string 1:-1
Enter string 2: 56
Enter string 3: dog
no of positive numbers entered 1
no of other strings entered 3
This is my current code I have not worked out yet how to find 'the no of other strings entered' yet as I am confused on why my code will not allow word input
def Is_Pos(whole_number):
global countervalue
if whole_number.is_integer()==True and whole_number >= 0:
countervalue += 1
def main():
loop=int(input("Enter 1 for a 'for' loop, 2 for a 'while' loop: "))
if loop==1:
print("You choose a 'for' loop")
global countervalue
countervalue=0
user_input=int(input("How many strings do you want to enter? "))
for num in range(1,user_input+1):
value=float(input("Enter string %a: "%num))
Is_Pos(value)
print("No of positive whole numbers entered", countervalue)
main()
This is the error that is displaying
value=float(input("Enter string %a: "%num))
ValueError: could not convert string to float: 'cat'